Wolfram Research

Function Repository Resource:

SendMailFromNotebook

Source Notebook

Send mail messages defined by sections in a notebook

Contributed by: Wolfram Staff

ResourceFunction["SendMailFromNotebook"][nb]

takes sections in nb to define mail messages, with the section title being the "To" address, the subsection title being the mail "Subject" and text cells being the mail "Body".

ResourceFunction["SendMailFromNotebook"][nb,assoc]

appends the elements in the association assoc to the definition of each mail message.

ResourceFunction["SendMailFromNotebook"][]

opens a basic template notebook for sending mail.

Details and Options

ResourceFunction["SendMailFromNotebook"][] creates a new notebook for composing an email with a send button.
Before sending mail, ResourceFunction["SendMailFromNotebook"] returns an interface that previews mail messages, then gives the option to send or cancel.
Within the mail notebook, the Section cell can contain multiple email addresses separated by commas or newline characters.
Subject lines can be given as Subsection or Subsubsection cells.
The body of messages can consist of multiple "Text" cells.
Explicit "From" and "FullName" elements should be given in assoc if these are to be included in mail messages. Otherwise, the default behavior of SendMail for the current account will be used.

Examples

Basic Examples

Open a notebook for composing an email:

In[1]:=
ResourceFunction["SendMailFromNotebook"][]
Out[1]=

Press the Send button in the notebook, or use SendMailFromNotebook on the NotebookObject to send:

In[2]:=
ResourceFunction["SendMailFromNotebook"][%]
Out[2]=

Generate the notebook, with some elements filled in:

In[3]:=
ResourceFunction[
 "SendMailFromNotebook"][<|"To" -> "testing@example.com", "Subject" -> "This is the subject", "Body" -> "This is the text of the email."|>]
Out[3]=

Create and save a notebook that you want to send as an email:

In[4]:=
nb = CreateDocument[{TextCell[$WolframID, "Section"], TextCell["my subject line", "Subsection"], TextCell["paragraph 1", "Text"], TextCell["paragraph 2", "Text"], ExpressionCell[Import["ExampleData/spikey.tiff"], "Output"]}];
In[5]:=
path = FileNameJoin[{$TemporaryDirectory, "mail.nb"}];
In[6]:=
NotebookSave[nb, path]
In[7]:=
NotebookClose[nb]

Send mail from the notebook:

In[8]:=
ResourceFunction["SendMailFromNotebook"][path]
Out[8]=

Or send mail with additional elements:

In[9]:=
ResourceFunction[
 "SendMailFromNotebook"][path, <|"Priority" -> 1, "Bcc" -> "foo@bar.com"|>]
Out[9]=

Process multiple emails from a file:

In[10]:=
nb = CreateDocument[{TextCell[$WolframID, "Section"], TextCell["subject 1", "Subsection"], TextCell["text 1", "Text"], TextCell[$WolframID, "Section"], TextCell["subject 2", "Subsection"], TextCell["text 2", "Text"]}];
In[11]:=
NotebookSave[nb, FileNameJoin[{$TemporaryDirectory, "mail.nb"}]]
In[12]:=
NotebookClose[nb]
In[13]:=
ResourceFunction["SendMailFromNotebook"][
 FileNameJoin[{$TemporaryDirectory, "mail.nb"}]]
Out[13]=

Send the same message to several recipients:

In[14]:=
nb = CreateDocument[{TextCell[$WolframID <> ", FirstName LastName <testing@example.com>", "Section"], TextCell["subject 1", "Subsection"], TextCell["text 1", "Text"]}];
In[15]:=
NotebookSave[nb, FileNameJoin[{$TemporaryDirectory, "mail.nb"}]]
In[16]:=
NotebookClose[nb]
In[17]:=
ResourceFunction["SendMailFromNotebook"][
 FileNameJoin[{$TemporaryDirectory, "mail.nb"}]]
Out[17]=

Resource History

License Information