【Python3】smtp发邮件(二)
sender = input('From:')
password = input('Password:')
receivers = input('To:')
content = input('Content:')
message = MIMEText(content, 'plain', 'utf-8')
message['From'] = Header(sender, 'utf-8')
message['To'] = Header(receivers, 'utf-8')
subject = input('Subject:')
message['Subject'] = Header(subject,'utf-8')
try:
smtpObj = smtplib.SMTP('smtp.trusfort.com',25)
smtpObj.login(sender,password)
smtpObj.sendmail(sender,receivers,message.as_string())
print("Success:邮件发送成功")
except smtplib.SMTPException:
print("Error:无法发送邮件")