Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want Mathematica to send me an email when the computation is finished. To that end, I have a cell with SendMail[...] which I place behind my computation in the evaluation queue. The problem I have is that I need to enter a password for my mail server. Doing that as an explicit rule leaves the password unencrypted and visible to everyone. On the other hand, setting "Password"->Automatic will only show a dialog box once the SendMail[] cell is evaluated. Is there a way to show the dialog box for password entry beforehand, such that I can enter the password and walk away?

share|improve this question
DialogInput? See first example in section "Scope". Mind you, as long as your machine is not locked, retrieving the password will still be trivial... – Yves Klett Aug 21 '13 at 11:03

2 Answers 2

up vote 17 down vote accepted

Here is one solution based on encoded package.

To create a pack you have to create a .m file (in this case mailPack.m). There is one example using gmail configuration:


sendMail::usage="sendMail[subject, body, to, file] send mail using myMail";

    "Password"->Uncompress@"myCompressedPassword", (*Use compress to create it*)

SetAttributes[sendMail, {ReadProtected,Locked}];


Now you can open another notebook, save in the same directory, and the do this to encode the first:


Now, if you try to open your mailPack.m as txt file, you will see that it is completely unreadable.

To use your sendMailfunction, copy your pack in the same directory of your file, then use SetDirectory@NotebookDirectory[], then use Needs["mailPack"]. If you use it all the time, copy the mailPack.m for the Application directory in your Mathematica folder (this command can help you SystemOpen@$UserBaseDirectory). Then you don't need the SetDirectory part neither to put the mailPack file in the same directory of your current notebook.

share|improve this answer
Interesting that @Leonid suggest DumpSave instead of Encode. Also related about security of encode here. – Murta Aug 21 '13 at 11:22
The juicy part is @RolfMertig´s comment on Locked in pre-9 versions... perhaps there is some more secure stuff possible via Java or similar? – Yves Klett Aug 21 '13 at 11:25
@YvesKlett, cool lock all function. link – Murta Aug 21 '13 at 11:31
This way it's more comfortable to open the code in front of another person, and if he is not Sheldon Cooper (with his eidetic memory) there is no problem. – Murta Aug 21 '13 at 12:02
  • Switch from SendMail to an email delivery service. The worst case scenario would be someone stealing your delivery password, which is no worse than the security you now have in the best SendMail case, because the very fact that SendMail works suggests that a spammer wouldn't even need your email password to send email on your behalf.
  • In your application replace SendMail with a URLExecute call to the API of an email delivery service such as Mailgun, see my Wolfram Community post Simple inexpensive delivery service outperforms SendMail. The posted example calls CloudDeploy, but you would just be calling the enclosed URLExecute directly from your Mathematica application.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.