Subversion Repositories SmartDukaan

Rev

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

Rev 5893 Rev 21100
Line 63... Line 63...
63
    mailServer.login(from_user, from_pwd)
63
    mailServer.login(from_user, from_pwd)
64
    mailServer.sendmail(from_user, to, msg.as_string())
64
    mailServer.sendmail(from_user, to, msg.as_string())
65
    # Should be mailServer.quit(), but that crashes...
65
    # Should be mailServer.quit(), but that crashes...
66
    mailServer.close()
66
    mailServer.close()
67
 
67
 
68
if __name__ == '__main__':
68
def mail_send_grid(from_email,from_user, from_pwd, to, subject, text, parts=[], cc=[], bcc=[]):
69
    parser = optparse.OptionParser()
69
    msg = MIMEMultipart()
70
    parser.add_option("-f", "--from",
70
    msg['From'] = from_email
71
                      dest="sender",
71
    msg['To'] = COMMASPACE.join(to)
72
                      type="string",
72
    if cc:
73
                      help="Send the mail as this user")
-
 
74
    parser.add_option("-p", "--password",
-
 
75
                      dest="password",
73
        to = to + cc
76
                      type="string",
74
        msg['Cc'] = COMMASPACE.join(cc)
77
                      help="Email account password of the sender")
-
 
78
    parser.add_option("-t", "--to",
75
    if bcc:
79
                      action="append",
76
        to = to + bcc
80
                      dest="to_addresses",
-
 
81
                      type="string",
77
    msg['Subject'] = subject
82
                      metavar="EMAIL",
78
    html_msg = MIMEText(text, 'html')
83
                      help="Send the mail to EMAIL")
-
 
84
    parser.add_option("-s", "--subject",
79
    msg.attach(html_msg)
85
                      dest="subject",
80
    for part in parts:
86
                      type="string",
81
        msg.attach(part)
87
                      help="Subject line of the email")
-
 
88
    parser.add_option("-x", "--text", dest="text",
82
    mailServer = smtplib.SMTP("smtp.sendgrid.net", 587)
89
                      type="string",
83
    mailServer.ehlo()
90
                      help="Email body text")
-
 
91
    parser.add_option("-a", "--attach",
84
    mailServer.starttls()
92
                      dest="attachments",
-
 
93
                      action="append",
-
 
94
                      type="string",
85
    mailServer.ehlo()
95
                      metavar="FILE",
86
    mailServer.login(from_user, from_pwd)
96
                      help="send FILE as an attachment. Use this option multiple times to send multiple attachments.")
-
 
97
    parser.set_defaults(sender="help@shop2020.in", password="5h0p2o2o")
87
    mailServer.sendmail(from_user, to, msg.as_string())
98
    (options, args) = parser.parse_args()
88
    # Should be mailServer.quit(), but that crashes...
99
    
-
 
100
    parts = []
-
 
101
    if options.attachments:
89
    mailServer.close()
102
        parts = [get_attachment_part(attachment) for attachment in options.attachments]
-
 
103
    
90
    
104
    mail(options.sender, options.password, options.to_addresses, options.subject, options.text, parts)
-
 
105
91
if __name__ == '__main__':
-
 
92
    mail_send_grid("sales-associates@profitmandi.com","apikey", "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", ["kshitij.sood@saholic.com"], "hi", "text", [get_attachment_part("/home/kshitij/sa/test.xls")],["thekshitijsood@gmail.com","kshitijsood.hpu@gmail.com"],["amit.gupta@saholic.com","kshitijsood@ymail.com"])
-
 
93
106
94