Ho un account yahoo
. Esiste un codice Python per inviare email dal mio account?Invio di e-mail tramite l'account yahoo in python
6
A
risposta
11
Sì; ecco il codice:
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('[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
Per supportare caratteri non ASCII; si potrebbe usare 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
ho collezionato la mia testa (brevemente) per quanto riguarda utilizzando server smtp di yahoo. 465 non funzionerebbe. Ho deciso di seguire la rotta TLS sulla porta 587 e sono stato in grado di autenticare e inviare email.
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()
Problemi correlati
- 1. Invio di email tramite email.mime.multipart in Python
- 2. Invio di email Devise tramite Resque
- 3. Invio di email da Django tramite SMTP ospitato
- 4. Invio di email tramite Mailgun con il pacchetto NodeMailer
- 5. Invio di email HTML tramite PHP: incluso il file HTML
- 6. Invio trasmissioni Email
- 7. Invio di email HTML in django
- 8. Invio di email Python TypeError: stringa o buffer previsto
- 9. Invio di posta tramite SmtpClient in .net
- 10. Invia email tramite Google Apps in C#
- 11. Invio di un file tramite socket TCP in Python
- 12. Invio di email html con script JQuery
- 13. Invio di SMS tramite Gmail tramite delphi
- 14. Invio di notifiche email per eventi tramite l'API di Google Calendar
- 15. Python: invio di dati tra due computer tramite prese
- 16. Invio dello screenshot tramite C#
- 17. Ottieni meteo Yahoo in celsius tramite la loro API
- 18. Invio di e-mail in asp.net tramite server host locale
- 19. Email più contatti in Python
- 20. Come inviare email tramite Vetro
- 21. Invio di e-mail Asp.Net tramite gmail
- 22. Trigger Build in Jenkins tramite EMAIL
- 23. inviare email tramite Gmail SMTP
- 24. Rails: Invia email tramite Gmail in produzione
- 25. Impossibile inviare email tramite openshift
- 26. Invio e ricezione di array tramite socket
- 27. Invio tasto "INVIO" tramite porta seriale
- 28. Invio di e-mail SMTP tramite Django nell'ambiente di produzione
- 29. Ottieni l'indirizzo email di Outlook tramite C#
- 30. Invio di una password tramite SSH o SCP con sottoprocesso.Popen
server.starttls() deve essere aggiunto prima della riga con server.login altrimenti genererà un'eccezione. – user6972
'Estensione AUTH SMTP non supportata dal server – Volatil3