0

I want to send email using Python and simultaneously want to write mail-message in a file as well.For sending mail I can do easily with smtplib but for saving part need your help.

My need is I am creating a webtool for my company where need to send a mail and have to send an update in every an hour so I have planned to save message into file and at the time of second send will call that file and will send with new update. If anyone knows other method then most welcome.

send code:

 import smtplib
 server = smtplib.SMTP('smtp.gmail.com', 587)
 server.ehlo()
 server.starttls()
 server.login("sender@gmail.com", "passwd")
 msg = "Hello World!"
 server.sendmail("sender@gmail.com", "receiver@gmailcom", msg)
 server.quit()

Thanks in advance

Vivek sinha
  • 21
  • 1
  • 10
  • Please [edit] your question and include the relevnat part of the code you use to build and send the email. Probably it is possible to save the email after building it. –  Jun 03 '16 at 07:45

1 Answers1

2

Well, all you need to do is:

file = open('myfile', 'w')
file.write(msg)
file.close()
Laszlowaty
  • 1,295
  • 2
  • 11
  • 19