5

How do I add the Reply To email header in Mailjet API? Or other headers?

Google search reveals the property ReplyEmail but that is only for Newsletter.Resource and not for Send.Resource.

goamn
  • 1,939
  • 2
  • 23
  • 39

2 Answers2

3

Using MailJet V3 API:

MailjetClient client = new MailjetClient("MJ_APIKEY_PUBLIC", "MJ_APIKEY_PRIVATE");
         MailjetRequest request = new MailjetRequest
         {
            Resource = Send.Resource,
         }
            .Property(Send.FromEmail, "pilot@mailjet.com")
            .Property(Send.FromName, "Mailjet Pilot")
            .Property(Send.Subject, "Your email flight plan!")
            .Property(Send.TextPart, "Dear passenger, welcome to Mailjet!")
            .Property(Send.HtmlPart, "<h3>Dear passenger, welcome to Mailjet!</h3>")
            .Property(Send.Recipients, new JArray {
                new JObject {
                 {"Email", "passenger@mailjet.com"}
                 }
                })
            .Property(Send.Headers, new JObject {
                {"Reply-To", "copilot@mailjet.com"}
                });
         MailjetResponse response = await client.PostAsync(request);

Using the Send.Headers, from this link: https://dev.mailjet.com/guides/#adding-email-headers-v3 And slightly different for V3.1: https://dev.mailjet.com/guides/#send-api-v3-to-v3-1

To save people time: if you are getting 200 success status code but no emails, check your allowed senders list. Also "Bcc" doesn't work with "Recipients", "Bcc" should be used with the "To" field.

goamn
  • 1,939
  • 2
  • 23
  • 39
2

Sending email with Reply-to using the MailJet PHP library:

$mj = new \Mailjet\Client('xxxxxxxxxxx','xxxxxxxxxxx',true,['version' => 'v3.1']);
$body = [
'Messages' => [
  [
    'From' => [
      'Email' => "",
      'Name' => ""
    ],
    'To' => [
      [
        'Email' => "", 
        'Name' => ""
      ]
    ],
    'Subject' => "", 
    'TextPart' => "", 
    'HTMLPart' => "", 
    'Headers' => [
      'Reply-To' => ""
    ]                           
  ]
 ]
];

$response = $mj->post(Resources::$Email, ['body' => $body]);
$response->success();
eyal_katz
  • 1,111
  • 10
  • 17