I have some code used to send emails. It works on windows but when I try run it on a mac (with the same user login as on the windows machine), it doesn’t send an email or return any errors.
Anyone have any experience with this kinda thing, or examples, tips, solutions pls?
import smtplib
import mimetypes
from email import encoders
from email.message import Message
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import platform
SERVER = "mail.myCompany.co.za"
COMMASPACE = ', '
SUBJECT = "testing"
TEXT = "mac dev test\n\nSent from: " + platform.platform()
TO = [ 'jared.glass@myCompany.co.za' ]
FROM = "jared.glass@myCompany.co.za"
# connect to the server
smtp = smtplib.SMTP( SERVER )
smtp.ehlo()
# if attachments are too big, try gain and just add them as links
# Create the container (outer) email message.
msg = MIMEMultipart()
msg['Subject'] = SUBJECT
msg['From'] = FROM
msg['To'] = COMMASPACE.join(TO)
msg.attach( MIMEText( TEXT , 'plain') )
smtp.sendmail( FROM , TO , msg.as_string() )
smtp.close()
print(" ---- SUCCESS ---- mail sent ---- ")
The sendmail call returned nothing – just {}. And finally I don’t know why but out of sheer annoyance I tried
and it seemed to fix the problem.
It doesn’t make sense to me that you would need to do this for the script to work on the mac as it worked perfectly fine on the windows machine WITHOUT the login… Grrrrr mac.
Thanks for the suggestions 🙂