我想通過直接連接到smtp.gmail.com
,直接從腳本發送電子郵件到Gmail電子郵件帳戶。如何在沒有身份驗證的情況下直接發送郵件到SMTP服務器?
但是,我不希望在腳本中使用gmail密碼。從我讀到的內容來看,Gmail似乎需要進行身份驗證,然後才能發送任何郵件,包括向其自己的用戶發送郵件。
我的問題是,郵件是如何從另一個SMTP服務器傳出的,因爲該SMTP服務器將不具有Gmail憑據。 Gmail是否只需要對「匿名」發件人進行身份驗證,並且由於我的腳本正在個人計算機上運行,因此安全性更高?這裏是python腳本我運行:
import smtplib
import email
msg = email.message.Message()
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
msg["Subject"] = "Test message"
server = smtplib.SMTP("smtp.gmail.com",587)
server.starttls()
server.ehlo_or_helo_if_needed()
try:
failed = server.sendmail("[email protected]","[email protected]", msg.as_string())
server.close()
except Exception as e:
print(e)
當我運行此腳本,輸出:
(530, b'5.5.1 Authentication Required. Learn more at
5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 fw5sm21125889wib.0', '[email protected]')
我的問題是,如何外部SMTP服務器避免這個問題?它們是否可以在本地腳本中進行復制,還是需要正確的反向DNS記錄,SPF記錄等?
這裏 「25」 代表了什麼? @MaK – 2015-11-30 09:14:30
25是SMTP端口,用於與郵件服務器進行通信。 https://en.m.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol – MaK 2015-12-01 11:48:43
是@Mak,但它是靜態的嗎?或動態?他們的任何端口是否可用? – 2015-12-08 14:30:35