簡體   English   中英

SMTP電子郵件腳本不適用於Mac,但適用於Windows

[英]SMTP Email script doesn't work on Mac but works on Windows

我有一些用於發送電子郵件的代碼。 它可以在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 ---- ")

sendmail調用未返回任何內容-僅返回{}。 最后我不知道為什么,但是出於純粹的煩惱,我嘗試了

smtp.starttls()
smtp.login('username', 'password')

而且似乎可以解決問題。

對我來說,讓腳本在Mac上運行不需要您這樣做,因為它無需登錄即可在Windows計算機上正常運行。

感謝您的建議:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM