简体   繁体   English

在Python中使用smtplib发送电子邮件

[英]Sending Emails With smtplib In Python

I am trying to send emails with Gmail through the SMTPlib, it works fine when I send them to myself, but every time I try to send an email to someone else it still sends it to my own email. 我正在尝试通过SMTPlib发送带有Gmail的电子邮件,当我发送给自己时,它可以正常工作,但每次我尝试向其他人发送电子邮件时,它仍会将其发送到我自己的电子邮件中。

import smtplib as s

username = raw_input("Gmail Username: ")
password = raw_input("Gmail Password: ")
obj = s.SMTP("smtp.gmail.com:587")
obj.starttls()
obj.login(username, password)
v_email = raw_input("Email: ")
email_message = raw_input("Message: ")
obj.sendmail(username, v_email, email_message)

查看示例http://docs.python.org/library/smtplib.html ,检查在传递给smtplib.sendmail()之前如何填充'msg'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM