Omk*_*kar 6 smtplib python-3.x
我想在没有登录 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()
Run Code Online (Sandbox Code Playgroud)
我希望应该在不询问用户 ID 和密码的情况下发送邮件但收到错误:
"smtplib.SMTPSenderRefused: (530, b'5.7.1 客户端未通过身份验证', 'from@Address.com')"
下面的代码对我有用。首先,我通过 Network Team 打开/启用端口 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)
server.ehlo()
server.starttls()
server.sendmail(fromAddr, toAddr, text)
server.quit()
Run Code Online (Sandbox Code Playgroud)
小智 5
我是这样用的。它在我的私人 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")
Run Code Online (Sandbox Code Playgroud)
小智 5
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21212 次 |
| 最近记录: |