[英]SMTP Email script doesn't work on Mac but works on Windows
I have some code used to send emails. 我有一些用于发送电子邮件的代码。 It works on windows but when I try run it on a mac (with the same user login as on the windows machine), it doesn't send an email or return any errors. 它可以在Windows上运行,但是当我尝试在Mac上运行时(用户登录名与Windows计算机相同),它不会发送电子邮件或返回任何错误。
Anyone have any experience with this kinda thing, or examples, tips, solutions pls? 任何人都对这种东西有经验,或者例子,技巧,解决方案请?
import smtplib
import mimetypes
from email import encoders
from email.message import Message
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import platform
SERVER = "mail.myCompany.co.za"
COMMASPACE = ', '
SUBJECT = "testing"
TEXT = "mac dev test\n\nSent from: " + platform.platform()
TO = [ 'jared.glass@myCompany.co.za' ]
FROM = "jared.glass@myCompany.co.za"
# connect to the server
smtp = smtplib.SMTP( SERVER )
smtp.ehlo()
# if attachments are too big, try gain and just add them as links
# Create the container (outer) email message.
msg = MIMEMultipart()
msg['Subject'] = SUBJECT
msg['From'] = FROM
msg['To'] = COMMASPACE.join(TO)
msg.attach( MIMEText( TEXT , 'plain') )
smtp.sendmail( FROM , TO , msg.as_string() )
smtp.close()
print(" ---- SUCCESS ---- mail sent ---- ")
The sendmail call returned nothing - just {}. sendmail调用未返回任何内容-仅返回{}。 And finally I don't know why but out of sheer annoyance I tried 最后我不知道为什么,但是出于纯粹的烦恼,我尝试了
smtp.starttls()
smtp.login('username', 'password')
and it seemed to fix the problem. 而且似乎可以解决问题。
It doesn't make sense to me that you would need to do this for the script to work on the mac as it worked perfectly fine on the windows machine WITHOUT the login... Grrrrr mac. 对我来说,让脚本在Mac上运行不需要您这样做,因为它无需登录即可在Windows计算机上正常运行。
Thanks for the suggestions :) 感谢您的建议:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.