Lefty.Email
0.2.0
dotnet tool install --global Lefty.Email --version 0.2.0
dotnet new tool-manifest
dotnet tool install --local Lefty.Email --version 0.2.0
#tool dotnet:?package=Lefty.Email&version=0.2.0
nuke :add-package Lefty.Email --version 0.2.0
lemail
.NET tool to send emails through SMTP, Resend, or Azure Communication Services.
Installing
To install the tool as a repository tool, run the following command in the root of your repository:
> dotnet tool install --local Lefty.Email --create-manifest-if-needed
If you'd rather have the tool installed globally in your machine, run the following command:
> dotnet tool install --global Lefty.Email
Senders
When using smtp sender (default):
| Env | M/O | Default | Description |
|---|---|---|---|
SMTP_HOST |
Mandatory | none | Hostname or IP address of SMTP server |
SMTP_PORT |
Optional | 587 |
Port number |
SMTP_SSL |
Optional | True |
Whether to use SSL |
SMTP_USERNAME |
Optional | null | Username for authentication |
SMTP_PASSWORD |
Required if username specified | null | Password |
When using resend sender:
| Env | M/O | Default | Description |
|---|---|---|---|
RESEND_APITOKEN |
Mandatory | none | API token, as obtained from dashboard |
> set EMAIL_SENDER=resend
> set RESEND_APITOKEN=<api>
When using acs sender (Azure Communication Services):
| Env | M/O | Default | Description |
|---|---|---|---|
ACS_CONNECTIONSTRING |
Either | none | Connection string, as obtained from Azure portal |
ACS_ENDPOINT |
Either | none | Endpoint URL, when authenticating with Entra ID |
Exactly one of ACS_CONNECTIONSTRING or ACS_ENDPOINT must be set.
> set EMAIL_SENDER=acs
> set ACS_CONNECTIONSTRING=endpoint=https://<resource>.communication.azure.com/;accesskey=<key>
When ACS_ENDPOINT is set, the tool authenticates using
DefaultAzureCredential,
which supports managed identity, workload identity, environment variables
and developer credentials (such as az login). For a user-assigned managed
identity, set AZURE_CLIENT_ID to the client id of the identity. The
identity must be granted a role with permission to send email on the
Communication Services resource.
> set EMAIL_SENDER=acs
> set ACS_ENDPOINT=https://<resource>.communication.azure.com/
Note that ACS ignores the display name of the sender: the sender address must be a MailFrom address of a domain linked to the resource, and the display name is configured there.
Example
The tool accepts a single argument, which is the name of a Json file.
> cat email.json
{
"from": "Master Yoda <yoda@dagobah.sw>",
"to": "Luke Skywalker <lskywalker19@tatooine.sw>",
"subject": "Reminder",
"htmlBody": "<h1>Use the force</h1>"
}
> dotnet lemail email.json
It is also possible to pipe JSON to the command:
> cat email.json | dotnet lemail --stdin
Usage patterns
The tool supports all of the following usage patterns to construct the email message to send:
- JSON (file, or piped in)
- Environment variables, only if
--envis provided) - CLI options
Json format
The format of the file is as follows:
| Property | Type | M/O | Description |
|---|---|---|---|
from |
Mandatory | Email sender | |
to |
Email, or Array of Emails | Mandatory | Email recipients |
cc |
Email, or Array of Emails | Optional | Additional email recipients |
bcc |
Email, or Array of Emails | Optional | Non-disclosed email recipients |
subject |
String | Mandatory | Subject of email message |
textBody |
String, or @Filename | Mandatory | Plain-text body |
htmlBody |
String, or @Filename | Mandatory | HTML body |
An Email can be expressed as follows:
lskywalker19@tatooine.sw- Just the e-email addressLuke Skywalker <lskywalker19@tatooine.sw>- With display name
Environment variables
The following variables will be evaluated, but only if --env option
is provided in the command line.
| Env | Type | Description |
|---|---|---|
EMAIL_FROM |
Sender email address | |
EMAIL_TO |
Emails | Semi colon seperated list of recipients |
EMAIL_SUBJECT |
String | Subject |
EMAIL_HTML |
File | File name of HTML body |
EMAIL_TEXT |
File | File name of text body |
CLI options
> dotnet lemail --help
Email sender
Usage: lemail [options] <InputFile>
Arguments:
InputFile Input JSON file
Options:
--version Show version information.
-f|--from Sender email address
-t|--to Recipient email address
-s|--subject Subject
-h|--html-file HTML file
-x|--text-file Text file
-X|--text Text content
--stdin Read JSON from stdin
-e|--env Load sender/recipient from environment variables
-?|--help Show help information
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.