0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00
logto/packages/connectors/connector-mailgun
2024-02-08 13:18:42 +08:00
..
src feat: create invitation (#5245) 2024-01-25 19:44:20 +08:00
CHANGELOG.md release: version packages (#5068) 2024-02-08 13:18:42 +08:00
logo.png feat: mailgun connector (#4281) 2023-08-03 04:38:09 +00:00
package.json release: version packages (#5068) 2024-02-08 13:18:42 +08:00
README.md refactor(connector): support mailgun endpoint (#4290) 2023-08-03 09:23:27 +00:00

Mailgun email connector

The official Logto connector for Mailgun email service.

Table of contents

Prerequisites

Basic configuration

  • Fill out the endpoint field when you are using a different Mailgun API endpoint, for example, EU region should be https://api.eu.mailgun.net. The default value is https://api.mailgun.net.
  • Fill out the domain field with the domain you have registered in your Mailgun account. This value can be found in the Domains section of the Mailgun dashboard. The domain should be in the format example.com, without the https:// or http:// prefix.
  • Fill out the apiKey field with the API key you have generated in your Mailgun account.
  • Fill out the from field with the email address you want to send emails from. This email address must be registered in your Mailgun account. The email address should be in the format Sender Name <sender@example.com>.

Deliveries

Config object

The "Deliveries" section allows you to configure the content of the emails to be sent in different scenarios. It is a JSON key-value map where the key is the usage type and the value is an object containing the content config for the email to be sent.

{
  "<usage-type>": {
    // ...
  }
}

Usage types

The following usage types are supported:

  • Register: The email to be sent when a user is registering.
  • SignIn: The email to be sent when a user is signing in.
  • ForgotPassword: The email to be sent when a user is resetting their password.
  • Generic: The email to be sent when a user is performing a generic action, for example, testing the email connector.

Note

If the usage type is not specified in the deliveries config, the generic email will be sent. If the generic email is not specified, the connector will return an error.

Content config

The connector supports both direct HTML content and Mailgun template. You can use one of them for each usage type.

In both subject and content, you can use the {{code}} placeholder to insert the verification code.

To use direct HTML content, fill out the following fields:

  • subject: The subject of the email to be sent.
  • replyTo: The email address to be used as the reply-to address.
  • html: (Required) The HTML content of the email to be sent.
  • text: The plain text version of the email to be sent.

To use Mailgun template, fill out the following fields:

  • subject: The subject of the email to be sent.
  • replyTo: The email address to be used as the reply-to address.
  • template: (Required) The name of the Mailgun template to be used.
  • variables: The variables to be passed to the Mailgun template. Should be a JSON key-value map since it will be stringified before sending to Mailgun. Note there's no need to include the code variable since it will be automatically added by the connector.

Example

The following is an example of the deliveries config:

{
  "Register": {
    "subject": "{{code}} is your verification code",
    "replyTo": "Foo <foo@bar.com>",
    "html": "<h1>Welcome to Logto</h1><p>Your verification code is {{code}}.</p>",
    "text": "Welcome to Logto. Your verification code is {{code}}."
  },
  "SignIn": {
    "subject": "Welcome back to Logto",
    "replyTo": "Foo <foo@bar.com>",
    "template": "logto-sign-in",
    "variables": {
      "bar": "baz"
    }
  }
}

Test Mailgun email connector

You can type in an email address and click on "Send" to see whether the settings can work before "Save and Done".

That's it. Don't forget to Enable connector in sign-in experience