Python uses the smtplib module to send emails through gmail

Source: Internet
Author: User

Python uses the smtplib module to send emails through gmail

This article mainly introduces how to use the smtplib module in python to send emails through gmail. It involves the skills related to sending emails using the smtplib module in Python. It is very simple and practical. If you need it, you can refer

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

Import smtplib

From email. MIMEMultipart import MIMEMultipart

From email. MIMEText import MIMEText

Fromaddr = 'fromaddr @ gmail.com'

Toaddr = 'toaddr @ gmail.com'

Text = 'test email message sent from Python Code'

Username = 'fromaddruser'

Password = 'fromaddrpassword'

Msg = MIMEMultipart ()

Msg ['from'] = fromaddr

Msg ['to'] = toaddr

Msg ['subobject'] = 'test'

Msg. attach (MIMEText (text ))

Server = smtplib. SMTP ('smtp .gmail.com: 8080 ')

Server. ehlo ()

Server. starttls ()

Server. ehlo ()

Server. login (username, password)

Server. sendmail (fromaddr, toaddr, msg. as_string ())

Server. quit ()

I hope this article will help you with Python programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.