Reputation: 1738
Email With Mandrill to multiple emailId but it only deliver to id which is first in the list to rest it does not send.I want to send mail to multiple users using mandrill API
here is my code :
class mandrillClass:
def mandrillMail(self,param):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart('alternative')
msg['Subject'] = param['subject']
msg['From'] = param['from']
msg['To'] = param['to']
html = param['message']
print html
text = 'dsdsdsdds'
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
username = '[email protected]'
password = 'uiyhiuyuiyhihuohohio'
msg.attach(part1)
msg.attach(part2)
s = smtplib.SMTP('smtp.mandrillapp.com', 587)
s.login(username, password)
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit()
and here i am calling the function
from API_Program import mandrillClass
msgDic = {}
msgDic['subject'] = "testing"
msgDic['from'] = "[email protected]"
#msgDic['to'] = '[email protected]','[email protected]'
COMMASPACE = ', '
family = ['[email protected]','[email protected]']
msgDic['to'] = COMMASPACE.join(family)
msgDic['message'] = "<div>soddjags</div>"
mailObj = mandrillClass()
mailObj.mandrillMail(msgDic)
Upvotes: 0
Views: 2481
Reputation: 6235
Since you're using smtplib, you'll want to review the documentation for that SMTP library on how you specify multiple recipients. SMTP libraries vary in how they handle multiple recipients. Looks like this StackOverflow post has information about passing multiple recipients with smtplib: How to send email to multiple recipients using python smtplib?
You need a list instead of just strings, so something like this:
msgDic['to'] = ['[email protected]','[email protected]']
So, your family variable is declared properly, and you shouldn't need to do anything to that.
Upvotes: 1
Reputation: 16029
Try:
msgDic['to'] = [{"email":fam} for fam in family]
From the docs it looks like they expect this structure:
msgDic['to'] = [ {"email":"[email protected]", "name":"a.b", "type":"to"},
{"email":"[email protected]", "name":"x.z", "type":"cc"}
]
where you can omit name
and type
.
Upvotes: 0