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

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.
Attachments can be inserted after the text cells for the body of the message. Attachments can be made by pasting an ExpressionCell or by dragging and dropping a file into the template notebook.

Examples

Basic Examples (5) 

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"}];
NotebookSave[nb, path];
NotebookClose[nb];

Send mail from the notebook:

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

Or send mail with additional elements:

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

Process multiple emails from a file:

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

Send the same message to several recipients:

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

Version History

  • 4.0.1 – 10 May 2021
  • 4.0.0 – 05 October 2020
  • 3.0.0 – 20 April 2020
  • 2.0.0 – 31 May 2019
  • 1.0.0 – 11 March 2019

License Information