我試圖發送電子郵件到專用SMTP服務器,可以做到使用python smtplib
如下sendgrid - 如何指定收件人SMTP服務器?
s = smtplib.SMTP(server, port)
s.sendmail(me, you, msg.as_string())
試圖將其轉換到Sendgrid(如天青塊SMTP),但它沒有選項指定一個專用SMTP服務器。
import sendgrid
import os
from sendgrid.helpers.mail import *
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("[email protected]")
to_email = Email("[email protected]")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)
任何幫助將不勝感激。
感謝
感謝您的回答。根本問題是SMTP Azure發送在Microsoft Azure上被阻止(我也懷疑AWS),他們建議使用中繼服務,如sendgrid。但是,如果我必須修改sendgrid以使用smtp,我懷疑我會以任何方式遇到Azure阻止問題。 – dopplesoldner
您必須創建一個靠近您的SMTP服務器的API端點來充當中繼。您在HTTPS中從Azure出去並指向API端點。你可以關閉這個問題,我們無法回答你的問題;) –