我有yahoo
帳戶。 是否有任何python代碼從我的帳戶發送電子郵件?在python中使用雅虎帳戶發送電子郵件
6
A
回答
11
是;這裏是代碼:
import smtplib
fromMy = '[email protected]' # fun-fact: from is a keyword in python, you can't use it as variable, did abyone check if this code even works?
to = '[email protected]'
subj='TheSubject'
date='2/1/2010'
message_text='Hello Or any thing you want to send'
msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % (fromMy, to, subj, date, message_text)
username = str('yourMai[email protected]')
password = str('yourPassWord')
try :
server = smtplib.SMTP("smtp.mail.yahoo.com",587)
server.login(username,password)
server.sendmail(fromMy, to,msg)
server.quit()
print 'ok the email has sent '
except :
print 'can\'t send the Email'
2
爲了支持非ascii字符;你可以使用email
package:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from email.header import Header
from email.mime.text import MIMEText
from getpass import getpass
from smtplib import SMTP_SSL
# provide credentials
login = '[email protected]'
password = getpass('Password for "%s": ' % login)
# create message
msg = MIMEText('message body…', 'plain', 'utf-8')
msg['Subject'] = Header('subject…', 'utf-8')
msg['From'] = login
msg['To'] = ', '.join([login, ])
# send it
s = SMTP_SSL('smtp.mail.yahoo.com', timeout=10) #NOTE: no server cert. check
s.set_debuglevel(0)
try:
s.login(login, password)
s.sendmail(msg['From'], msg['To'], msg.as_string())
finally:
s.quit()
5
我苦苦使用雅虎的SMTP服務器關於頭(簡述)。 465就是行不通。我決定通過端口587去TLS路由,並且我能夠驗證併發送電子郵件。
import smtplib
from email.mime.text import MIMEText
SMTP_SERVER = "smtp.mail.yahoo.com"
SMTP_PORT = 587
SMTP_USERNAME = "username"
SMTP_PASSWORD = "password"
EMAIL_FROM = "[email protected]"
EMAIL_TO = "[email protected]"
EMAIL_SUBJECT = "REMINDER:"
co_msg = """
Hello, [username]! Just wanted to send a friendly appointment
reminder for your appointment:
[Company]
Where: [companyAddress]
Time: [appointmentTime]
Company URL: [companyUrl]
Change appointment?? Add Service??
change notification preference (text msg/email)
"""
def send_email():
msg = MIMEText(co_msg)
msg['Subject'] = EMAIL_SUBJECT + "Company - Service at appointmentTime"
msg['From'] = EMAIL_FROM
msg['To'] = EMAIL_TO
debuglevel = True
mail = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
mail.set_debuglevel(debuglevel)
mail.starttls()
mail.login(SMTP_USERNAME, SMTP_PASSWORD)
mail.sendmail(EMAIL_FROM, EMAIL_TO, msg.as_string())
mail.quit()
if __name__=='__main__':
send_email()
相關問題
- 1. 發送電子郵件給雅虎和Hotmail用戶?
- 2. Lightopenid和雅虎用戶電子郵件
- 3. 在雅虎帳戶上未接收到PHP電子郵件
- 4. 無法使用vb.net發送雅虎電子郵件
- 5. 使用雅虎SMTP發送電子郵件
- 6. 如何使用雅虎管道發送電子郵件?
- 7. 發送電子郵件從PHP使用雅虎smtp
- 8. 雅虎smtp發送電子郵件時發生錯誤
- 9. 發送電子郵件Yahoo帳戶
- 10. 雅虎不接受我發送給它的電子郵件
- 11. 有谷歌或雅虎API來發送電子郵件?
- 12. 獲取用戶電子郵件雅虎Oauth(使用Scribe-Java API)
- 13. 雅虎沒有提供電子郵件
- 14. Java電子郵件和雅虎
- 15. 利用Google帳戶憑據在Android中發送電子郵件
- 16. 郵件不發送與雅虎
- 17. 使用python計算電子郵件帳戶中的郵件數
- 18. 使用Outlook和Delphi從特定帳戶發送電子郵件
- 19. 使用Google Apps帳戶從網站發送電子郵件
- 20. 使用PHP發送電子郵件到Gmail帳戶
- 21. 選擇使用哪個域帳戶發送電子郵件
- 22. 使用Android帳戶憑據發送電子郵件
- 23. 無法使用smtp gmail帳戶發送電子郵件
- 24. VB .Net使用Gmail帳戶發送電子郵件
- 25. 如何使用appengine從非gmail帳戶發送電子郵件
- 26. 雅虎OpenID + OAuth,如何獲取用戶登錄電子郵件
- 27. 未能在Gmail雅虎服務器發送電子郵件正在
- 28. 發送郵件之前選擇電子郵件帳戶?
- 29. PHP郵件功能不發送電子郵件到Gmail帳戶
- 30. 發送用戶激活電子郵件的新帳戶
server.starttls()應該添加到server.login之前,否則會引發異常。 – user6972 2014-02-17 08:39:46
'服務器不支持SMTP AUTH擴展.' – Volatil3 2017-07-17 06:40:53