неділя, 1 лютого 2015 р.

How to send email with Python help. Smtplib

Lets suppose that you already had working smtp server (like Postfix or Exim) and it works on 25 port. You want to send email using your Python script. I hope this article will help you to do that.

At first make sure that you server can send emails.  Send simple email using bash or shell:

# mail -s “Hello world” test@example.com

And check mailbox test@example.com. Ok, I hope that everything is fine.

Now open your favourite editor and pass there text like that:


Cool. But maybe you want to send email using your existed Gmail or other box with credentials. Look at my second example:


We need to use real mailbox and real password for email sending. Also gmail/yahoo uses secured ports like 587 (STARTTLS) so you need to use starttls() method. You can type anything what you want in To and From fields, because of nature of SMTP protocol.

My last example about how to sent html letters:


Hope this one is clear.

Links:

http://www.simplehelp.net/2008/12/01/how-to-send-email-from-the-linux-command-line/
http://www.tutorialspoint.com/python/python_sending_email.htm

Немає коментарів:

Дописати коментар