1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| from_email = { "user": 'From Email', "password": 'Password or Authorization Code', "host": 'SMTP service' }
yag = yagmail.SMTP( user=from_email['user'], password=from_email['password'], host=from_email['host'] )
subject = ['CDUT STA 验证码'] contents = generate_contents(username, captcha)
def generate_contents(username, code): return [''' <table width="600" cellspacing="0" border="0" align="center" style="border: rgba(0, 0, 0, 0.3) 1px solid"> <tbody style="align-items: center"> <tr style=" height: 64px; background-color: #415a94; color: #fff;"> <td style="text-align: center; font-size: 21px;">CDUT STA</td> </tr>
<tr> <td style=" display: table-cell; padding: 8% 0; color: #000; text-align: center; font-size: 21px; "> 邮箱验证码 </td> </tr>
<tr> <td style="display: table-cell; padding: 0 6%; color: #333"> 尊敬的 {} , 您好! </td> </tr>
<tr> <td style="display: table-cell; padding: 2% 6% 10% 6%; color: #333"> 您的验证码是: <span style="font-weight: 600; color: red">{}</span> ,请在 5 分钟内进行验证。如果该验证码不为您本人申请,请无视。 </td> </tr>
<tr> <td style="background: #f7f7f7; display: table-cell; padding: 2% 6%"> <a href="https://www.baidu.com" style="color: #929292">返回</a> </td> </tr> </tbody> </table>'''.format(username, code).replace('\n', '')]
yag.send(to_email, subject, contents)
|