-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJangoSMTP.py
More file actions
59 lines (47 loc) · 1.61 KB
/
JangoSMTP.py
File metadata and controls
59 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
####################################################################
# JangoSMTP.py
# downloaded from jangomail.com/Tutorials/JangoSMTP.py
# This example shows how to send email through the jangosmtp service
# from within a python program.
####################################################################
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# This from-address must be stored in your JangoSMTP settings
FromAddress = "YourEmail@Address.com"
# set the recipient
ToAddress = "Recipient@Domain.com"
# create the message object
msg = MIMEMultipart('alternative')
msg['Subject'] = "JangoSMTP from Python Test"
msg['From'] = FromAddress
msg['To'] = ToAddress
# Create the body of the message (a plain-text and an HTML version).
text = "This is a plain text email sent from a python program!"
html = """\
<html>
<head></head>
<body>
<p>
This is an html email sent from a <b>python</b> program!
</p>
</body>
</html>
"""
# JangoSMTP credentials
username = "Your JangoSMTP Username"
password = "Your JangoSMTP Password"
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# Attach parts into message container.
msg.attach(part1)
msg.attach(part2)
# Open a connection to the JangoSMTP server
s = smtplib.SMTP('relay.jangosmtp.net', 25)
# Authenticate
s.login(username, password)
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(FromAddress, ToAddress, msg.as_string())
s.quit()