1+ __author__ = 'Sujit Mandal'
2+ #Date : 07-09-2020
3+ import smtplib
4+
5+ '''
6+ # Author : Sujit Mandal
7+ Github : https://github.com/sujitmandal
8+ Pypi : https://pypi.org/user/sujitmandal/
9+ LinkedIn : https://www.linkedin.com/in/sujit-mandal-91215013a/
10+ '''
11+
12+ #E-mail login credential
13+ gmail_id = ('' ) #sender g-mail id
14+ password = ('' ) #sender g-mail password
15+
16+ #reciver mail id's
17+ reciver_mail_id = [
18+ 19+ 20+ 21+ '............................' ,
22+ '.............................' ,
23+ 'reciver_mail_id_N [email protected] ' ,
24+ ]
25+ #main subject
26+ subject = ('' ) #mail subject
27+ #mail contain
28+ mail_contain = ('' ) #mail contain
29+
30+
31+ class loginCredential :
32+ def login (self ,gmail_id , password ):
33+ self .gmail_id = gmail_id
34+ self ._password = password
35+
36+ server = smtplib .SMTP ('smtp.gmail.com' , 587 )
37+ server .ehlo ()
38+ server .starttls ()
39+ server .ehlo ()
40+ server .login (self .gmail_id , self ._password )
41+ return (server )
42+
43+ class reciverCredential (loginCredential ):
44+ def reciver_mail (self , reciver_mail_id ):
45+ self .reciver_mail_id = reciver_mail_id
46+
47+ mail_id = []
48+ for i in reciver_mail_id :
49+ mail_id .append (i )
50+ return (mail_id )
51+
52+ class gmail (reciverCredential ):
53+ def send_mail (self , subject , mail_containt ):
54+ server = self .login (self .gmail_id , self ._password )
55+ reciver_mail_id = self .reciver_mail (self .reciver_mail_id )
56+
57+ containt = (f'subject: { subject } \n \n { mail_containt } ' )
58+
59+ server .sendmail (
60+ self .gmail_id ,
61+ reciver_mail_id ,
62+ containt
63+ )
64+ if len (reciver_mail_id ) == 1 :
65+ print ('Mail has been sent to this : {}' .format (reciver_mail_id ),'Address.' )
66+ else :
67+ print ('Mail has been sent to these : {}' .format (reciver_mail_id ),'Address.' )
68+ server .quit ()
69+
70+
71+
72+ if __name__ == '__main__' :
73+ mail = gmail ()
74+ mail .login (gmail_id , password )
75+ mail .reciver_mail (reciver_mail_id )
76+ mail .send_mail (subject , mail_contain )
0 commit comments