magic.lambda.mail 13.3.4

.NET Standard 2.0
Install-Package magic.lambda.mail -Version 13.3.4
dotnet add package magic.lambda.mail --version 13.3.4
<PackageReference Include="magic.lambda.mail" Version="13.3.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magic.lambda.mail --version 13.3.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: magic.lambda.mail, 13.3.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install magic.lambda.mail as a Cake Addin
#addin nuget:?package=magic.lambda.mail&version=13.3.4

// Install magic.lambda.mail as a Cake Tool
#tool nuget:?package=magic.lambda.mail&version=13.3.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Sending and retrieving emails from Hyperlambda

SMTP and POP3 helpers for Magic. More specifically, this project contains the following slots.

  • [mail.smtp.send] - Sends email(s) through an SMTP server
  • [mail.pop3.fetch] - Retrieves emails from a POP3 server

Sending email(s)

mail.smtp.send

   server
      host:foo.com
      port:123
      secure:true
      username:xxx
      password:yyy

   message

      to
         John Doe:john@doe.com
      from
         Jane Doe:jane@doe.com
      subject:Subject line

      entity:text/plain
         content:Body content

You can send multiple [message] objects at the same time, using the same SMTP connection and credentials. This allows you to connect once to the SMTP server, and use the same connection to send multiple emails.

The entirety of the [server] node above is optional, and if it's not given, it will be fetched from your configuration settings. You can also override only one or two parts in your [server] segment above, and have the system read the rest of the settings from your application's configuration. In addition, the [from] node is also optional, assuming you have a default from configured in your configuration settings. Below are the keys used to fetch configuration settings for SMTP connections, and from object, if not explicitly given as part of the invocation.

  • magic.smtp.host
  • magic.smtp.port
  • magic.smtp.secure
  • magic.smtp.username
  • magic.smtp.password
  • magic.smtp.from.name
  • magic.smtp.from.address

An example of how your configuration might look like, if you choose to use configuration settings, instead of having to supply server configuration every time you invoke the slot, can be found below.

{
  "magic":{
    "smtp":{
      "host":"smtp.gmail.com",
      "port":465,
      "secure":true,
      "username":"username@gmail.com",
      "password":"gmail-password",
      "from": {
        "name":"John Doe",
        "address":"john@doe.com"
      }
    }
  }
}

FYI - If you exchange the above username/password combination, and open your GMail account for "insecure apps", the above will allow you to send emails using your GMail account.

Assuming you have the above somewhere in your configuration, you can construct and send an email using something like the following. Which probably makes things more convenient, allowing you to avoid thinking about connection settings, from addresses, etc - And leave this as a part of your deployment transformation pipeline(s), etc.

mail.smtp.send

   message
      to
         Jane Doe:jane@doe.com
      subject:Subject line

      entity:text/plain
         content:Body content

You can also add [cc], [bcc] and [reply-to] recipients for your emails, using the same structure you're using for [to]. In addition you can attach files to your messages, by instead of adding a [content] node to your invocation, adding a [filename] node, with a relative path pointing to the file you want to attach to your message. Below is an example of an email with a single attachment.

mail.smtp.send

   message
      to
         Jane Doe:jane@doe.com
      subject:Subject line

      entity:multipart/mixed

        entity:text/plain
           content:Body content

        entity:text/plain
           filename:/files/foo.txt

To construct your email's [message] part, see the documentation for the magic.lambda.mime project.

Retrieving emails

To retrieve emails from a POP3 server is equally easy. Below is an example.

mail.pop3.fetch

   server
      host:foo.com
      port:123
      secure:true
      username:xxx
      password:yyy

   max:int:50
   raw:bool:false

   .lambda

      /*
       * Some lambda object invoked once for every email fetched.
       * Given message as [.message] node structured as lambda.
       */

Just like its SMTP counterpart, the entirety of the above [server] node is optional, and fetched from your configuration if ommitted. Below are the keys used to fetch configuration settings for your POP3 connection, if not explicitly given as part of invocation.

  • magic.pop3.host
  • magic.pop3.port
  • magic.pop3.secure
  • magic.pop3.username
  • magic.pop3.password

You can find an example of how your configuration might look like below if you choose to use configuration settings instead of having to supply server configuration every time you invoke the slot.

{
  "magic":{
    "pop3":{
      "host":"pop.gmail.com",
      "port":995,
      "secure":true,
      "username":"username@gmail.com",
      "password":"gmail-password",
    }
  }
}

FYI - If you exchange the above username/password combination, and open up your GMail account for "insecure apps", the above will allow you to send emails using your GMail account.

Notice, if [raw] is true, the message will not be parsed and turned into a structural lambda object, but passed into your [.lambda] as its raw MIME message instead. The default value for [raw] is false. Your [.lambda] callback will be invoked for each message with a [.message] node, containing the structured/raw version of the MIME message wrapping the actual email message. Refer to the magic.lambda.mime project's documentation for details to understand this structure. If you choose to retrieve messages in [raw] format, the message node's value will contain the raw MIME message as text. If you choose this path, and you later want to actually parse the message, to make it become a structured lambda object - You can use the [mime.parse] slot from magic.lambda.mime.

Project website

The source code for this repository can be found at github.com/polterguy/magic.lambda.mail, and you can provide feedback, provide bug reports, etc at the same place.

Quality gates

  • Build status
  • Quality Gate Status
  • Bugs
  • Code Smells
  • Coverage
  • Duplicated Lines (%)
  • Lines of Code
  • Maintainability Rating
  • Reliability Rating
  • Security Rating
  • Technical Debt
  • Vulnerabilities
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on magic.lambda.mail:

Package Downloads
magic.library

Helper project for Magic to wire up everything easily by simply adding one package, and invoking two simple methods. When using Magic, this is (probably) the only package you should actually add, since this package pulls in everything else you'll need automatically, and wires up everything sanely by default. To use package go to https://polterguy.github.io

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
13.3.4 264 5/9/2022
13.3.0 162 5/1/2022
13.2.0 207 4/21/2022
13.1.0 230 4/7/2022
13.0.0 102 4/5/2022
12.0.3 219 3/14/2022
11.0.5 233 3/2/2022
11.0.4 150 2/22/2022
11.0.3 153 2/9/2022
11.0.2 156 2/6/2022
11.0.1 127 2/5/2022
10.0.21 148 1/28/2022
10.0.20 135 1/27/2022
10.0.19 140 1/23/2022
10.0.18 117 1/17/2022
10.0.15 290 12/31/2021
10.0.14 196 12/28/2021
10.0.7 598 12/22/2021
10.0.5 294 12/18/2021
10.0.2 201 12/14/2021
9.9.9 881 11/29/2021
9.9.3 325 11/9/2021
9.9.2 251 11/4/2021
9.9.0 357 10/30/2021
9.8.9 303 10/29/2021
9.8.7 273 10/27/2021
9.8.6 259 10/27/2021
9.8.5 319 10/26/2021
9.8.0 657 10/20/2021
9.7.9 275 10/19/2021
9.7.5 745 10/14/2021
9.7.0 392 10/9/2021
9.6.6 613 8/14/2021
9.5.3 1,281 7/20/2021
9.2.0 2,393 5/26/2021
9.1.4 589 4/21/2021
9.1.0 448 4/14/2021
9.0.0 421 4/5/2021
8.9.9 506 3/30/2021
8.9.3 784 3/19/2021
8.9.2 476 1/29/2021
8.9.1 479 1/24/2021
8.9.0 556 1/22/2021
8.6.9 1,725 11/8/2020
8.6.6 1,053 11/2/2020
8.6.0 2,060 10/28/2020
8.5.0 943 10/23/2020
8.4.0 2,997 10/13/2020
8.3.1 1,412 10/5/2020
8.3.0 645 10/3/2020
8.2.2 1,080 9/26/2020
8.2.1 684 9/25/2020
8.2.0 701 9/25/2020
8.1.19 228 9/24/2020
8.1.18 1,750 9/21/2020
8.1.17 2,200 9/13/2020
8.1.16 328 9/13/2020
8.1.15 947 9/12/2020
8.1.11 1,263 9/11/2020
8.1.10 662 9/6/2020
8.1.9 673 9/3/2020
8.1.8 672 9/2/2020
8.1.7 567 8/28/2020
8.1.4 565 8/25/2020
8.1.3 637 8/18/2020
8.1.2 580 8/16/2020
8.1.1 678 8/15/2020
8.1.0 303 8/15/2020
8.0.1 1,438 8/7/2020
8.0.0 593 8/7/2020
7.0.1 717 6/28/2020
7.0.0 691 6/28/2020
5.0.1 1,404 5/29/2020
5.0.0 649 5/29/2020