我可以让smtplib发送到其他电子邮件地址,但由于某种原因,它不能发送到我的手机上。
import smtplib
msg = 'test'
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login("<username>","<password>")
server.sendmail(username, "<number>@vtext.com", msg)
server.quit()当地址是gmail帐户时,消息发送成功,并且使用gmail原生界面向手机发送消息效果很好。短信号码有什么不同?
注意:使用set_debuglevel()我可以断定smtplib相信消息是成功的,所以我相当确信这种差异与vtext数字的行为有关。
发布于 2012-01-24 16:07:22
该电子邮件被拒绝,因为它看起来不是电子邮件(没有任何收件人或主题字段)
这是可行的:
import smtplib
username = "account@gmail.com"
password = "password"
vtext = "1112223333@vtext.com"
message = "this is the message to be sent"
msg = """From: %s
To: %s
Subject: text-message
%s""" % (username, vtext, message)
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(username,password)
server.sendmail(username, vtext, msg)
server.quit()发布于 2015-04-09 03:37:54
这个被接受的答案在我的Python 3.3.3中不起作用。我还必须使用MIMEText:
import smtplib
from email.mime.text import MIMEText
username = "account@gmail.com"
password = "password"
vtext = "1112223333@vtext.com"
message = "this is the message to be sent"
msg = MIMEText("""From: %s
To: %s
Subject: text-message
%s""" % (username, vtext, message))
server = smtplib.SMTP('smtp.gmail.com',587)
# server.starttls()
server.login(username,password)
server.sendmail(username, vtext, msg.as_string())
server.quit()https://stackoverflow.com/questions/8982572
复制相似问题