By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Sending an email using smtp lib with body containing multiple lines and variables

P: 2
I have cracked sending an email containing text and a value from a variable using some code I found online
Expand|Select|Wrap|Line Numbers
  1. SERVER = "server"
  2.  
  3. FROM = "from address"
  4. TO = ["to address"]
  5. SUBJECT = "subject"
  6.  
  7. TEXT = "Line Count     :- " + str(linecount)
  8.  
  9. # Prepare actual message
  10.  
  11. message = """\
  12. From: %s
  13. To: %s
  14. Subject: %s
  15.  
  16. %s
  17. """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  18.  
  19. server = smtplib.SMTP(SERVER)
  20. server.sendmail(FROM, TO, message)
  21. server.quit()
However I would like to add extra lines for other totals. I don't seem to be able to figure out how to do this.

Any help would be greatly appreciated.
Aug 13 '14 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Here is one possibility:
Expand|Select|Wrap|Line Numbers
  1. >>> ("Line Count     :- %s\n"
  2. ...  "another line count: %s" % (linecount, linecount*2))
  3. 'Line Count     :- 6\nanother line count: 12'
  4. >>> print ("Line Count     :- %s\n"
  5. ...     "another line count: %s" % (linecount, linecount*2))
  6. Line Count     :- 6
  7. another line count: 12
  8. >>> 
Aug 13 '14 #2

P: 2
Thanks - that did the required job
Aug 14 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.