我想发送电子邮件而不用Python登录服务器。我正在使用Python 3.6。 我尝试了一些代码,但收到一个错误。这是我的代码:
import smtplib
smtpServer='smtp.yourdomain.com'
fromAddr='from@Address.com'
toAddr='to@Address.com'
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(smtpServer)
server.set_debuglevel(1)
server.sendmail(fromAddr, toAddr, text)
server.quit()
我希望发送邮件时无需询问用户ID和密码,但会收到错误消息:
“ smtplib.SMTPSenderRefused:(530,b'5.7.1客户端未通过身份验证,'from @ Address.com')”
答案 0 :(得分:4)
import win32com.client as win32
outlook=win32.Dispatch('outlook.application')
mail=outlook.CreateItem(0)
mail.To='To address'
mail.Subject='Message subject'
mail.Body='Message body'
mail.HTMLBody='<h2>HTML Message body</h2>' #this field is optional
# To attach a file to the email (optional):
attachment="Path to the attachment"
mail.Attachments.Add(attachment)
mail.Send()
答案 1 :(得分:1)
我正在这样使用。在我的私人SMTP服务器上,对我来说是正常的工作。
import smtplib
host = "server.smtp.com"
server = smtplib.SMTP(host)
FROM = "testpython@test.com"
TO = "bla@test.com"
MSG = "Subject: Test email python\n\nBody of your message!"
server.sendmail(FROM, TO, MSG)
server.quit()
print ("Email Send")
答案 2 :(得分:0)
以下代码对我有用。 首先,我通过网络团队打开/启用了端口25,并在程序中使用了。
import smtplib
smtpServer='smtp.yourdomain.com'
fromAddr='from@Address.com'
toAddr='to@Address.com'
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(smtpServer,25)
s.ehlo()
s.starttls()
server.sendmail(fromAddr, toAddr, text)
server.quit()