Apr-24-2017, 05:18 AM
(This post was last modified: Apr-24-2017, 05:18 AM by ur00361883.)
THe code works fine for a single email address.
But if I add multiple email addresses, then it is being received by only the first email adress and the others are not getting that.
But I can see them in the to list, in the received mail and even in the sent items of gmail.When I click on reply all manually then they are receiving.
Please suggest.
But if I add multiple email addresses, then it is being received by only the first email adress and the others are not getting that.
But I can see them in the to list, in the received mail and even in the sent items of gmail.When I click on reply all manually then they are receiving.
Please suggest.
import time,datetime
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import binascii
import struct
#import datetime as dt
import string
def send_gmail2(subject,attach_file=None):
email_content = """
Hi All,
%s.
This mail sent from build machine.
""" % ( subject)
new_msg = {
"content": email_content,
"from_address": "[email protected]",
"to_address": "[email protected],[email protected]",
"subject": subject
}
process_send_gmail("upd.bin", new_msg,attach_file)
def process_send_gmail(upd_path, msg, attach_file=None):
#account = get_cred_from_file(upd_path)
account = get_cred()
msg_body = MIMEMultipart()
msg_body['From'] = msg["from_address"]
msg_body['To'] = msg["to_address"]
msg_body['Subject'] = msg["subject"]
msg_body.attach(MIMEText(msg["content"]))
if attach_file is not None:
attach_file = attach_file.replace("\"", "").replace("\'", "")
file_name = os.path.basename(attach_file)
att1 = MIMEText(open(attach_file, 'rb').read(), 'base64', 'utf8')
att1["Content-Type"] = 'application/octet-stream'
att1["Content-Disposition"] = 'attachment; filename="%s"' % file_name
msg_body.attach(att1)
print "Start to send mail"
s = smtplib.SMTP("smtp.gmail.com")
# s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.login(account["user"], account["pwd"])
s.sendmail(msg["from_address"], msg["to_address"], msg_body.as_string())
s.quit()
print "Mail sent"
def get_cred():
return {"user": "[email protected]", "pwd": "****"}
send_gmail2("Ant War file creation completed with success or failure.Please check the log file: ")
