0

I tried to run the following python script (copied from http://www.tutorialspoint.com/python/python_sending_email.htm) on a remote server to send an Email. I successfully received the Email in my mailbox, but unfortunately the content is always empty. Another problem is, if I slightly change the message within """From: xxx """, say delete this part From: sender Name, then I could even receive the empty Email. What is the magic going on inside message line """xxx"""?

import smtplib
def send_Email2():

    sender = 'username@company.com'
    receivers = "receivername@company.com"    
    message = """From: Sender Name  <username@company.com>
         To: Receiver Name <receivername@company.com>
         Subject: SMTP e-mail test

         This is a test e-mail message.
         """

   try:
       smtpObj = smtplib.SMTP('1xx.128.2.xxx',25)
       smtpObj.sendmail(sender, receivers, message)  
       print "Successfully sent email"
   except SMTPException:
       print "Error: unable to send email"    
GAVD
  • 1,977
  • 3
  • 22
  • 40
leoking87
  • 13
  • 6
  • Maybe [this](http://stackoverflow.com/questions/11796664/smtplib-sends-blank-message-if-the-message-contain-certain-characters) helps – GAVD Jul 20 '16 at 03:54

1 Answers1

-1

Have you tried like below:

message['Subject'] = 'SMTP e-mail test'
message['From'] = 'username@company.com'
message['To'] = 'receivername@company.com'
Santanu Dey
  • 2,900
  • 3
  • 24
  • 38
  • It is the right direction. I ended up using this: http://stackoverflow.com/questions/3362600/how-to-send-email-attachments-with-python. – leoking87 Jul 25 '16 at 16:39