Subversion Repositories SmartDukaan

Rev

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

Rev 1246 Rev 2123
Line 4... Line 4...
4
from email.MIMEMultipart import MIMEMultipart
4
from email.MIMEMultipart import MIMEMultipart
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
import optparse
9
 
10
 
10
def get_attachment_part(filename):
11
def get_attachment_part(filename):
11
    part = MIMEBase('application', 'octet-stream')
12
    part = MIMEBase('application', 'octet-stream')
12
    part.set_payload(open(filename, 'rb').read())
13
    part.set_payload(open(filename, 'rb').read())
13
    Encoders.encode_base64(part)
14
    Encoders.encode_base64(part)
Line 34... Line 35...
34
    mailServer.sendmail(from_user, to, msg.as_string())
35
    mailServer.sendmail(from_user, to, msg.as_string())
35
    # Should be mailServer.quit(), but that crashes...
36
    # Should be mailServer.quit(), but that crashes...
36
    mailServer.close()
37
    mailServer.close()
37
 
38
 
38
if __name__ == '__main__':
39
if __name__ == '__main__':
-
 
40
    parser = optparse.OptionParser()
-
 
41
    parser.add_option("-f", "--from", dest="sender",
-
 
42
                   type="string",
-
 
43
                   help="Send the mail as this user")
-
 
44
    parser.add_option("-p", "--password", dest="password",
39
    mail("cnc.center@shop2020.in",
45
                   type="string",
-
 
46
                   help="Email account password of the sender")
-
 
47
    parser.add_option("-t", "--to", dest="to",
40
         "puttherightpasswdhere",
48
                   type="string",
-
 
49
                   help="Send the mail to this user")
-
 
50
    parser.add_option("-s", "--subject", dest="subject",
41
         "some.person@some.address.com",
51
                   type="string",
-
 
52
                   help="Subject line of the email")
-
 
53
    parser.add_option("-x", "--text", dest="text",
42
         "Hello from python!",
54
                   type="string",
43
         "This is an email sent with python",
55
                   help="Email body text")
-
 
56
    parser.add_option("-a", "--attach", dest="attachment",
-
 
57
                    metavar="FILE",
-
 
58
                    help="send FILE as an attachment")
-
 
59
    parser.set_defaults(sender="help@shop2020.in", password="5h0p2o2o")
-
 
60
    (options, args) = parser.parse_args()
-
 
61
    
-
 
62
    if options.attachment:
-
 
63
        part = get_attachment_part(options.attachment)
-
 
64
    else:
44
         None)
65
        part = None
-
 
66
    
-
 
67
    mail(options.sender, options.password, options.to, options.subject, options.text, part)
45
68