简体   繁体   English

SMTP电子邮件脚本不适用于Mac,但适用于Windows

[英]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.

相关问题 Python脚本在Windows上不起作用(但适用于mac) - Python script doesn't work on Windows (but works on mac) python电子邮件脚本在Mac OS X 10.9上不起作用 - python email script doesn't work on mac os x 10.9 使用Python和Gmail SMTP服务器发送电子邮件不适用于附件 - Sending email with Python and Gmail SMTP server doesn't work with attachment 使用 cron 运行脚本在 mac 上不起作用 - Running script with cron doesn't work on mac 我的脚本适用于 Windows,但不适用于 Linux-关于文件夹路径 - My script works on Windows but doesn't work on Linux-About Folder Path 在电子邮件 BytesIO 中发送带有附件的消息不起作用 - 没有显示错误 - Python/Smtp/Email - Sending message with attachment in email BytesIO doesn't work - No errors shown - Python/Smtp/Email python exifread在linux和mac上排序图像,在Windows上不起作用 - python exifread sort images on linux and mac, doesn't work on windows 脚本无法在ubuntu中运行,但可以在Windows中正常运行 - Script doesn't run in ubuntu but works fine in windows `import pyspark`可在Jupyter中使用,但不适用于python shell / script - `import pyspark` works in Jupyter, but doesn't work with python shell/script Boolean 索引器脚本可以正常工作但无法正常工作 - Boolean indexer script works without Error but doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM