我正在尝试发送一封构造HTML代码的电子邮件,如下面的代码所示,现在的问题是,当电子邮件发送出去时,HTML表被截断了(请参见下图),而如果我从HTML代码看起来不错,我不知道如何调试它?有关如何解决此问题的任何指导?
def construct_html(gerrit_author_gerrit_url_age_dict, gerrit_author_count, merge_conflict_gerrits):
logger.info("Constructing html...")
icount = 1
GerritMailBody = "<html><body><b><FONT COLOR=\"Maroon\">Hi,<br><br>Please find the list of pending Open Gerrit IDs in below projects </font><br><br> "
GerritMailBody = GerritMailBody + \
"<table border=\"1\"><tr bgcolor=\"lightyellow\"><th>S.No</th><th>Owner</th><th>Count</th><th>GerritList/Age</th</tr>"
for key in gerrit_author_count:
logger.info('key %s' % key)
GerritMailBody = GerritMailBody + "<tr>"
GerritMailBody = GerritMailBody + "<td>" + str(icount) + "</td>"
#GerritMailBody = GerritMailBody + "<td>" + key.rstrip('\n') + "</td>"
GerritMailBody = GerritMailBody + "<td>" + \
"name1" + str(icount) + "</td>"
#GerritMailBody = GerritMailBody + "<td>" + str(gerrit_author_count[key]) + "</td>"
GerritMailBody = GerritMailBody + "<td>" + \
"name2" + str(icount) + "</td>"
#GerritMailBody = GerritMailBody + "<td>" + str(gerrit_author_gerrit_url_age_dict[key]) + "</td>"
GerritMailBody = GerritMailBody + "<td>" + \
"name3" + str(icount) + "</td>"
GerritMailBody = GerritMailBody + "</tr>"
icount = icount + 1
GerritMailBody = GerritMailBody + "</table>"
GerritMailBody = GerritMailBody + \
"<br><br><i><b><FONT COLOR=\"NAVY\">Thanks and Regards,<br>WiFi DEV</i></b><br></body></html>"
return GerritMailBody
电子邮件:
msg['From'] = sender
msg['To'] = ', '.join(receivers)
msg['Cc'] = ', '.join(cc)
#msg['Cc'] = cc
msg["Content-Type"] = "text/html"
try:
mail = smtplib.SMTP('relay.company.com', 25)
msg.attach(MIMEText(body, 'html'))
msg.add_header('reply-to', REPLY_TO_ADDRESS)
mail.sendmail(sender, receivers+cc, msg.as_string())
logger.info('Email sent successfully %s %s'%(receivers,cc))
except Exception as e:
logger.error('Problem sending email')
logger.error('%s' % e)
HTML代码:
<html>
<body><b>
<FONT COLOR="Maroon">Hi,<br><br>Please find the list of pending Open Gerrit IDs in below projects </font>
<br><br>
<table border="1">
<tr bgcolor="lightyellow">
<th>S.No</th>
<th>Owner</th>
<th>Count</th>
<th>GerritList/Age</th</tr> <tr>
<td>1</td>
<td>name11</td>
<td>name21</td>
<td>name31</td>
</tr>
<tr>
<td>2</td>
<td>name12</td>
<td>name22</td>
<td>name32</td>
</tr>
<tr>
<td>3</td>
<td>name13</td>
<td>name23</td>
<td>name33</td>
</tr>
<tr>
<td>4</td>
<td>name14</td>
<td>name24</td>
<td>name34</td>
</tr>
<tr>
<td>5</td>
<td>name15</td>
<td>name25</td>
<td>name35</td>
</tr>
<tr>
<td>6</td>
<td>name16</td>
<td>name26</td>
<td>name36</td>
</tr>
<tr>
<td>7</td>
<td>name17</td>
<td>name27</td>
<td>name37</td>
</tr>
<tr>
<td>8</td>
<td>name18</td>
<td>name28</td>
<td>name38</td>
</tr>
<tr>
<td>9</td>
<td>name19</td>
<td>name29</td>
<td>name39</td>
</tr>
<tr>
<td>10</td>
<td>name110</td>
<td>name210</td>
<td>name310</td>
</tr>
<tr>
<td>11</td>
<td>name111</td>
<td>name211</td>
<td>name311</td>
</tr>
<tr>
<td>12</td>
<td>name112</td>
<td>name212</td>
<td>name312</td>
</tr>
<tr>
<td>13</td>
<td>name113</td>
<td>name213</td>
<td>name313</td>
</tr>
<tr>
<td>14</td>
<td>name114</td>
<td>name214</td>
<td>name314</td>
</tr>
<tr>
<td>15</td>
<td>name115</td>
<td>name215</td>
<td>name315</td>
</tr>
<tr>
<td>16</td>
<td>name116</td>
<td>name216</td>
<td>name316</td>
</tr>
<tr>
<td>17</td>
<td>name117</td>
<td>name217</td>
<td>name317</td>
</tr>
<tr>
<td>18</td>
<td>name118</td>
<td>name218</td>
<td>name318</td>
</tr>
<tr>
<td>19</td>
<td>name119</td>
<td>name219</td>
<td>name319</td>
</tr>
<tr>
<td>20</td>
<td>name120</td>
<td>name220</td>
<td>name320</td>
</tr>
<tr>
<td>21</td>
<td>name121</td>
<td>name221</td>
<td>name321</td>
</tr>
<tr>
<td>22</td>
<td>name122</td>
<td>name222</td>
<td>name322</td>
</tr>
<tr>
<td>23</td>
<td>name123</td>
<td>name223</td>
<td>name323</td>
</tr>
<tr>
<td>24</td>
<td>name124</td>
<td>name224</td>
<td>name324</td>
</tr>
<tr>
<td>25</td>
<td>name125</td>
<td>name225</td>
<td>name325</td>
</tr>
<tr>
<td>26</td>
<td>name126</td>
<td>name226</td>
<td>name326</td>
</tr>
<tr>
<td>27</td>
<td>name127</td>
<td>name227</td>
<td>name327</td>
</tr>
<tr>
<td>28</td>
<td>name128</td>
<td>name228</td>
<td>name328</td>
</tr>
<tr>
<td>29</td>
<td>name129</td>
<td>name229</td>
<td>name329</td>
</tr>
<tr>
<td>30</td>
<td>name130</td>
<td>name230</td>
<td>name330</td>
</tr>
<tr>
<td>31</td>
<td>name131</td>
<td>name231</td>
<td>name331</td>
</tr>
<tr>
<td>32</td>
<td>name132</td>
<td>name232</td>
<td>name332</td>
</tr>
<tr>
<td>33</td>
<td>name133</td>
<td>name233</td>
<td>name333</td>
</tr>
<tr>
<td>34</td>
<td>name134</td>
<td>name234</td>
<td>name334</td>
</tr>
<tr>
<td>35</td>
<td>name135</td>
<td>name235</td>
<td>name335</td>
</tr>
<tr>
<td>36</td>
<td>name136</td>
<td>name236</td>
<td>name336</td>
</tr>
<tr>
<td>37</td>
<td>name137</td>
<td>name237</td>
<td>name337</td>
</tr>
<tr>
<td>38</td>
<td>name138</td>
<td>name238</td>
<td>name338</td>
</tr>
<tr>
<td>39</td>
<td>name139</td>
<td>name239</td>
<td>name339</td>
</tr>
<tr>
<td>40</td>
<td>name140</td>
<td>name240</td>
<td>name340</td>
</tr>
<tr>
<td>41</td>
<td>name141</td>
<td>name241</td>
<td>name341</td>
</tr>
<tr>
<td>42</td>
<td>name142</td>
<td>name242</td>
<td>name342</td>
</tr>
<tr>
<td>43</td>
<td>name143</td>
<td>name243</td>
<td>name343</td>
</tr>
<tr>
<td>44</td>
<td>name144</td>
<td>name244</td>
<td>name344</td>
</tr>
<tr>
<td>45</td>
<td>name145</td>
<td>name245</td>
<td>name345</td>
</tr>
<tr>
<td>46</td>
<td>name146</td>
<td>name246</td>
<td>name346</td>
</tr>
<tr>
<td>47</td>
<td>name147</td>
<td>name247</td>
<td>name347</td>
</tr>
<tr>
<td>48</td>
<td>name148</td>
<td>name248</td>
<td>name348</td>
</tr>
<tr>
<td>49</td>
<td>name149</td>
<td>name249</td>
<td>name349</td>
</tr>
<tr>
<td>50</td>
<td>name150</td>
<td>name250</td>
<td>name350</td>
</tr>
<tr>
<td>51</td>
<td>name151</td>
<td>name251</td>
<td>name351</td>
</tr>
<tr>
<td>52</td>
<td>name152</td>
<td>name252</td>
<td>name352</td>
</tr>
</table><br><br><i><b>
<FONT COLOR="NAVY">Thanks and Regards,<br>WiFi DEV</i>
</b><br></body>
</html>