-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendmail.py
More file actions
34 lines (29 loc) · 1.04 KB
/
sendmail.py
File metadata and controls
34 lines (29 loc) · 1.04 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
from smtplib import SMTP
import email.message
import re
def sendmailg(gserver , gport ,guser, gpass , mailfrom , mailto , subject , msg , ishtml = 0):
mailmsg = email.message.Message()
mailmsg['From'] = mailfrom
mailmsg['To'] = mailto
mailmsg['Subject'] = subject
if ishtml == 1:
mailmsg.add_header('Content-Type','text/html')
else:
mailmsg.add_header('Content-Type','text/plain')
mailmsg.set_payload (msg, 'utf-8')
with SMTP(gserver , gport) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login(guser, gpass)
smtp.set_debuglevel(1)
smtp.sendmail(mailfrom, mailto,mailmsg.as_string())
smtp.quit()
gserver = 'smtp.smtpserver.com'
gport = 587 # or 25 whatever you use
guser = ''
gpass = ''
mailfrom = 'test@test.com'
mailto = 'test1@test.com,test2@test.com'
subject = 'test'
msg = "<html><head></head><body><a href=\"http://www.example.com/\">Please Click the link :)</a></body></html>"
sendmailg(gserver , gport , guser, gpass , mailfrom , mailto , subject , msg , 1)