Skip to main content

wolfram cloud - Encrypt the password used for SendMail


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?



Answer



In general SendMail should not access an email account that stores important emails or that functions to reset the passwords of other online accounts. Such a valuable email account should be protected by two-factor authentication as well as user-managed access such as OAuth, and so forth. Because SendMail does not support any such features it can not access an truly secure email account. Rather than accept inadequate security on an important email account, it is much better to setup a separate email account especially for SendMail to access. If this special account is on gmail, then SendMail will require the Allow less secure apps setting. In addition, because it will only be used with SendMail the need to encrypt its password will depend solely the SendMail application’s security needs.



Besides setting up an email account especially for SendMail, there are at least two other email solutions to consider.


If you’re developing web applications, then you may already be using the free version of the Wolfram Development Platform. If you’re not at least at the $20/month Explorer plan, then upgrade and you will be able to deploy and call a SendMail API in the Wolfram Cloud:


CloudDeploy[
APIFunction[
{ "To" -> <|"Interpreter" -> "EmailAddress"|>,
"Subject" -> "String",
"Body" -> "String" },
SendMail[#] &],
FileNameJoin[{$CloudRootDirectory, "WolframCloudSandboxEmail"}],
Permissions -> "Public" ]


You only need to do the above CloudDeploy once. Then every time you want to send an email, just call the API from your desktop:


URLExecute[
FileNameJoin[{$CloudRootDirectory, "WolframCloudSandboxEmail"}],
{ "To" -> "YOUR-NAME ",
"Subject" -> "Wolfram Cloud Sandbox Email",
"Body" -> "Here is the body of the message." } ]

If for some reason you don’t want a public API that sends you email, then deploy the API as a private cloud object, add the Username and Password options to URLExecute, and protect it by the encoded package approach in Murta’s answer:


URLExecute[

FileNameJoin[{$CloudRootDirectory, "WolframCloudPrivateSandboxEmail"}],
{ "To" -> "YOUR-NAME ",
"Subject" -> "Wolfram Cloud Private Object Sandbox Email",
"Body" -> "Here is the body of the message." },
"Username" -> "YOUR-WOLFRAM-ID",
"Password" -> "YOUR-WOLFRAM-CLOUD-PASSWORD" ]

On the other hand, if you’re developing applications that have the potential to generate a significant volume of email, you probably are already using or at least considering an email delivery service. Calling such a service will be among your standard approaches to sending an email. For example, you can easily setup and use a Mailgun sandbox:


URLFetch["https://api.mailgun.net/v3/YOUR-SANDBOX-DOMAIN-NAME/messages",
"Method" -> "POST",

"MultipartElements" ->
{ {"from", "text/plain"} ->
"Mailgun Sandbox ",
{"to", "text/plain"} -> "YOUR-NAME ",
{"subject", "text/plain"} -> "Mailgun Sandbox Email",
{"text", "text/plain"} -> "Here is the body of the message." },
"Username" -> "api",
"Password" -> "YOUR-PRIVATE-API-KEY"]

Assuming that the mail delivery service is also being used to send other important emails, then its password could again be protected by the approach in Murta’s answer.



Comment 2/9/16:


As originally posted this answer simply alerted readers to the email delivery service alternative to SendMail and left it to them to decide on its suitablity for their application. This updated answer adds a Wolfram Development Platform alternative and specifies circumstances that might favor each solution.


Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.