Code Monkey home page Code Monkey logo

functiontosendemailwithmailkit's Introduction

Azure Function to Send Email with MailKit

The proyect consists of an Azure function that is triggered by an http request to send an email using MailKit client library

This can be useful if you want to send an email in response to a webhook setup on another system. Most of the samples available on GitHub that send email with Azure functions use the SendGrid library. This library and service is great if you plan to send a lot of emails. But if you just need occasional emails, the MailKit client library should be more than enough. BTW, I think the MailKit library is awesome.

Local Configuration

If you want to test the function locally in Visual Studio, please setup your local.settings.json this way:

{
	"IsEncrypted": false,
	"Values": {
		"AzureWebJobsStorage": "UseDevelopmentStorage=true",
		"FUNCTIONS_WORKER_RUNTIME": "dotnet",
		"EmailHost": "{YOUR-SMTP-HOST}",
		"EmailPort": "{YOUR-SMTP-PORT}",
		"EmailUser": "{YOUR-USER}",
		"EmailPassword": "{YOUR-PASSWORD}",
		"EmailFromEmail": "{YOUR-FROM-EMAIL}",
		"EmailFromName": "{YOUR-FROM-NAME}",
		"EmailHostUsesLocalCertificate": "false"
	}
}

Modify the "EmailToSend" class to fit your needs

The function parses the http request body to populate the class called: "EmailToSend". This class has 4 properties: "To", "Subject", "PlainBody" and "HtmlBody". Currently, the JSON to populate this class should be:

{
	"To": "{TO-EMAIL-ADDRESS}",
	"Subject": "{SUBJECT-OF-THE-EMAIL}",
	"PlainBody": "{BODY-OF-THE-EMAIL-IN-PLAIN-TEXT}",
	"HtmlBody": "{BODY-OF-THE-EMAIL-IN-HTML}"
}

However, depending on the webhook that you use, you should modify the "EmailToSend" class to adapt it to the JSON that you receive.

Some considerations

  • If the "To" email is not provided, the function will use the same email as the "From"
  • You may provide more than one email address for recipients by separating them with a semicolon (;)
  • When deploying the function to Azure, make sure to configure all the "Email..." parameters in the application settings
  • If you require more security for your email credentials, you may choose to use the Key Vault service instead

I hope this helps! ;)

functiontosendemailwithmailkit's People

Contributors

orodriguezv avatar

Stargazers

 avatar Asha Yalla avatar Bas Wanders avatar Martin Stühmer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.