Subversion Repositories SmartDukaan

Rev

Rev 1180 | Rev 2123 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1180 Rev 1246
Line 5... Line 5...
5
from email.MIMEBase import MIMEBase
5
from email.MIMEBase import MIMEBase
6
from email.MIMEText import MIMEText
6
from email.MIMEText import MIMEText
7
from email import Encoders
7
from email import Encoders
8
import os
8
import os
9
 
9
 
-
 
10
def get_attachment_part(filename):
-
 
11
    part = MIMEBase('application', 'octet-stream')
-
 
12
    part.set_payload(open(filename, 'rb').read())
-
 
13
    Encoders.encode_base64(part)
-
 
14
    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
-
 
15
    return part
-
 
16
    
10
def mail(from_user, from_pwd, to, subject, text, part=None):
17
def mail(from_user, from_pwd, to, subject, text, part=None):
11
    msg = MIMEMultipart()
18
    msg = MIMEMultipart()
12
    
19
    
13
    msg['From'] = from_user
20
    msg['From'] = from_user
14
    msg['To'] = to
21
    msg['To'] = to
Line 27... Line 34...
27
    mailServer.sendmail(from_user, to, msg.as_string())
34
    mailServer.sendmail(from_user, to, msg.as_string())
28
    # Should be mailServer.quit(), but that crashes...
35
    # Should be mailServer.quit(), but that crashes...
29
    mailServer.close()
36
    mailServer.close()
30
 
37
 
31
if __name__ == '__main__':
38
if __name__ == '__main__':
32
    attach="my_picture.jpg"
-
 
33
    part = MIMEBase('application', 'octet-stream')
-
 
34
    part.set_payload(open(attach, 'rb').read())
-
 
35
    Encoders.encode_base64(part)
-
 
36
    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach))
-
 
37
    
-
 
38
    mail("cnc.center@shop2020.in",
39
    mail("cnc.center@shop2020.in",
39
         "puttherightpasswdhere",
40
         "puttherightpasswdhere",
40
         "some.person@some.address.com",
41
         "some.person@some.address.com",
41
         "Hello from python!",
42
         "Hello from python!",
42
         "This is an email sent with python",
43
         "This is an email sent with python",