Skip to content
Last updated

Sending your first email

First, define the sender and recipient email as environment variables. Keep in mind that the sender email should be validated in your Mailjet account (your signup email address will be automatically validated).

Mac OS/Linux

export $SENDER_EMAIL='Enter your sender email address here'
export $RECIPIENT_EMAIL='Enter your recipient email address here'

Windows

export $SENDER_EMAIL='Enter your sender email address here'
export $RECIPIENT_EMAIL='Enter your recipient email address here'

Next, use the code sampe to send a message.

Sample Message

# Run:
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3.1/send \
	-H 'Content-Type: application/json' \
	-d '{
		"Messages":[
				{
						"From": {
								"Email": "$SENDER_EMAIL",
								"Name": "Me"
						},
						"To": [
								{
										"Email": "$RECIPIENT_EMAIL",
										"Name": "You"
								}
						],
						"Subject": "My first Mailjet Email!",
						"TextPart": "Greetings from Mailjet!",
						"HTMLPart": "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!"
				}
		]
	}'

API Response

# Run:
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3.1/send \
	-H 'Content-Type: application/json' \
	-d '{
		"Messages":[
				{
						"From": {
								"Email": "$SENDER_EMAIL",
								"Name": "Me"
						},
						"To": [
								{
										"Email": "$RECIPIENT_EMAIL",
										"Name": "You"
								}
						],
						"Subject": "My first Mailjet Email!",
						"TextPart": "Greetings from Mailjet!",
						"HTMLPart": "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!"
				}
		]
	}'

Congratulations - you have successfully sent your first email!

Info

Save the MessageID- You will need it in the next section to access detailed information about the sent email.