magic.lambda.mail 10.0.18

Install-Package magic.lambda.mail -Version 10.0.18
dotnet add package magic.lambda.mail --version 10.0.18
<PackageReference Include="magic.lambda.mail" Version="10.0.18" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magic.lambda.mail --version 10.0.18
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: magic.lambda.mail, 10.0.18"
#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=10.0.18

// Install magic.lambda.mail as a Cake Tool
#tool nuget:?package=magic.lambda.mail&version=10.0.18
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] and [bcc] 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

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
10.0.18 0 1/17/2022
10.0.15 146 12/31/2021
10.0.14 96 12/28/2021
10.0.7 376 12/22/2021
10.0.5 186 12/18/2021
10.0.2 165 12/14/2021
9.9.9 843 11/29/2021
9.9.3 275 11/9/2021
9.9.2 213 11/4/2021
9.9.0 315 10/30/2021
9.8.9 226 10/29/2021
9.8.7 227 10/27/2021
9.8.6 219 10/27/2021
9.8.5 258 10/26/2021
9.8.0 573 10/20/2021
9.7.9 235 10/19/2021
9.7.5 652 10/14/2021
9.7.0 354 10/9/2021
9.6.6 574 8/14/2021
9.5.3 1,141 7/20/2021
9.2.0 2,168 5/26/2021
9.1.4 549 4/21/2021
9.1.0 412 4/14/2021
9.0.0 362 4/5/2021
8.9.9 395 3/30/2021
8.9.3 590 3/19/2021
8.9.2 382 1/29/2021
8.9.1 352 1/24/2021
8.9.0 409 1/22/2021
8.6.9 1,471 11/8/2020
8.6.6 837 11/2/2020
8.6.0 1,587 10/28/2020
8.5.0 750 10/23/2020
8.4.0 2,280 10/13/2020
8.3.1 1,119 10/5/2020
8.3.0 514 10/3/2020
8.2.2 868 9/26/2020
8.2.1 538 9/25/2020
8.2.0 567 9/25/2020
8.1.19 190 9/24/2020
8.1.18 1,330 9/21/2020
8.1.17 1,714 9/13/2020
8.1.16 290 9/13/2020
8.1.15 725 9/12/2020
8.1.11 973 9/11/2020
8.1.10 507 9/6/2020
8.1.9 535 9/3/2020
8.1.8 561 9/2/2020
8.1.7 454 8/28/2020
8.1.4 449 8/25/2020
8.1.3 484 8/18/2020
8.1.2 472 8/16/2020
8.1.1 557 8/15/2020
8.1.0 267 8/15/2020
8.0.1 1,145 8/7/2020
8.0.0 481 8/7/2020
7.0.1 608 6/28/2020
7.0.0 550 6/28/2020
5.0.1 1,122 5/29/2020
5.0.0 512 5/29/2020