How to send emails with Mailgun

What code do I need to use to send emails with Mailgun?
5 Replies
kapa.ai
kapa.ai2w ago
Hi @ArDev. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To send emails with Mailgun in Wasp, you need to follow these steps: 1. Set the provider to Mailgun in the main.wasp file:
app Example {
...
emailSender: {
provider: Mailgun,
}
}
app Example {
...
emailSender: {
provider: Mailgun,
}
}
Source (https://wasp-lang.dev/docs/advanced/email#using-the-mailgun-provider) 2. Get the Mailgun API key and domain and add them to your .env.server file:
MAILGUN_API_KEY=
MAILGUN_DOMAIN=
MAILGUN_API_KEY=
MAILGUN_DOMAIN=
Source (https://wasp-lang.dev/docs/advanced/email#using-the-mailgun-provider) 3. Use the emailSender from the wasp/server/email module to send emails:
import { emailSender } from "wasp/server/email";

// In some action handler...
const info = await emailSender.send({
from: {
name: "John Doe",
email: "[email protected]",
},
to: "[email protected]",
subject: "Saying hello",
text: "Hello world",
html: "Hello <strong>world</strong>",
});
import { emailSender } from "wasp/server/email";

// In some action handler...
const info = await emailSender.send({
from: {
name: "John Doe",
email: "[email protected]",
},
to: "[email protected]",
subject: "Saying hello",
text: "Hello world",
html: "Hello <strong>world</strong>",
});
Source (https://wasp-lang.dev/docs/advanced/email#javascript-api) Please note that the send method accepts an object with the following fields: from, to, subject, text, and html. The from field is optional if you set up the defaultFrom field in the emailSender dict in the Wasp file. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ArDev, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ArDev
ArDev2w ago
@kapa.ai how to get the api key?
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you. One moment! :books: ---------------------- To get the Mailgun API key, follow these steps: 1. Go to Mailgun (https://www.mailgun.com/) and create an account. 2. Go to API Keys (https://app.mailgun.com/app/account/security/api_keys) and create a new API key. 3. Copy the API key and add it to your .env.server file. Your .env.server file should look like this:
MAILGUN_API_KEY=your_api_key_here
MAILGUN_DOMAIN=your_domain_here
MAILGUN_API_KEY=your_api_key_here
MAILGUN_DOMAIN=your_domain_here
Replace your_api_key_here with the API key you got from Mailgun. Source (https://wasp-lang.dev/docs/advanced/email#using-the-mailgun-provider) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ArDev, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ArDev
ArDev2w ago
@kapa.ai how to get server_url? how do i get it from railway
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you. One moment! :books: ---------------------- To get the server URL from Railway, follow these steps: 1. Go to your Railway dashboard (https://railway.app/dashboard). 2. Click on your project. 3. Go to the server instance's Settings tab, and click Generate Domain. The generated domain is your server URL. You can use this URL as the WASP_SERVER_URL in your environment variables. Source (https://wasp-lang.dev/docs/advanced/deployment/manually#railway-server-client-and-database) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ArDev, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Want results from more Discord servers?
Add your server