我有一些用于发送电子邮件的代码。它可以在 Windows 上运行,但是当我尝试在 Mac 上运行它(使用与 Windows 机器上相同的用户登录名)时,它不会发送电子邮件或返回任何错误。
有人对这种事情有任何经验,或者例子,提示,解决方案吗?
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 ---- ")