0

I wrote a script in python 3 to send a notification mail to list of stakeholders. I have observed that the last address in the mail received gets trimmed off the moment I give more than 255 characters in the "To" field.

Sample Code:

#me == the sender's email address
me = "[email protected]"
#you == the recipient's email address
you = "[email protected];[email protected];..."
msg['To'] = you
msg = MIMEMultipart('alternative')
msg['Subject'] = "Test mail"
msg['From'] = me
msg['To'] = you

part1 = MIMEText(text, 'plain')
part2 = MIMEText(messages, 'html')

msg.attach(part1)
msg.attach(part2)

s = smtplib.SMTP('localhost')
s.sendmail(me, you, msg.as_string())

For example, in the you field, pers[email protected], if s is the 255th character, then in the output mail, recipients field will be till pers from the left, rest gets trimmed off. How to overcome these?

Also, few questions:

  • Please provide the RFC or documentation on these. I checked in rfc822. Not much info present.
  • Is this related to Mime or smtplib module?
Dr. Essen
  • 603
  • 2
  • 9
  • 25

1 Answers1

0

Yes, using recipients as list and then using the join to make the recipient string works even for characters>=255.

(Use "," instead of "';" as separater)

Syntax that worked for me:

you = ["[email protected]", "[email protected]", ...]
msg["to"] = ",".join(you)
s.send_message(msg)