3

I have the following mathematica code to send me an email once a calculation is done. The code to calculate is saved in the 'code' variable.

SendMail["To" -> "jondoe@gmail.com", 
 "Subject" -> "Calculation Done", 
 "Body" -> 
  Evaluate[
    ToExpression[code]], 
 "From" -> "jondoe@gmail.com", 
 "Server" -> "smtp.gmail.com", 
 "UserName" -> "jondoe@gmail.com", 
 "Password" -> Automatic, "PortNumber" -> 587, 
 "EncryptionProtocol" -> "StartTLS"]

When I run this code it sends the email fine, except instead of the message body being the result of the code, there is a gif image of the result as an attachment. I can add ToString before the Evaluate to solve this, except this makes me not able to send images or graphics.

How can I have SendMail send strings as the message body and images as attachments?

Nico A
  • 3,634
  • 1
  • 15
  • 28
  • 1
    Can you provide a minimal example of code? Do you need a result from code to be automatically split to strings and images and images to be put in attachments? I'm asking because I'm not sure. – Kuba Jun 13 '16 at 07:32
  • @Kuba The things in code will be really simple, one line commands. There will be 1 result that will either be an image or a string. I don't need the result to be split up, I just need it to be an attachment if it's an image and in the message body if it's a string. It will never have to have both. – Nico A Jun 13 '16 at 12:47
  • So why aren't you using AttachedExpressions or AttachedFiles options? – Kuba Jun 13 '16 at 12:48
  • @Kuba Sorry if this is an obvious solution, I'm pretty new to mathematica. I know about AttachedFiles, but if the output is text, not graphics, sending it as an attached file would send it as an image, which I don't want. I want it to be an attatched file if it is an image/graphics object, and in the message body if it is text. – Nico A Jun 13 '16 at 13:36

0 Answers0