mailjet-apiv3-dotnet icon indicating copy to clipboard operation
mailjet-apiv3-dotnet copied to clipboard

Mailjet API version

Open fabr2004 opened this issue 2 years ago • 9 comments

At Mailjet Dev guide it is stated that API 3.1 was released +5 years ago (source). This Github project seems to run older API version 3. Is this correct?

fabr2004 avatar Nov 28 '23 14:11 fabr2004

Currently Mailjet API is spread under 3 versions: https://dev.mailjet.com/email/reference/overview/versioning/

Regarding the Github Mailjet api wrapper project:

SendTransactionalEmail methods in MailjetClient use API 3.1 version:

image

Basically client wrapper will determine what API version to call under the hood (V3, V3.1 or V4). Example:

image

dmytrosvystun88 avatar Nov 28 '23 22:11 dmytrosvystun88

Thanks for the clarification.

I was trying to implement Mailjet Dev guide (https://dev.mailjet.com/email/guides/send-api-v31/) to send transactional e-mails. The guide states (see below) to place Version = ApiVersion.V3_1 but this was not allowed, caused an error. We had <package id="Mailjet.Api" version="3.0.0" targetFramework="net48" />.

While investigating this I noticed Nuget package is described as "Official C# client library For Mailjet API version 3" and has "project URL" pointed here. So, since Mailjet informs latest e-mail API to be v3.1, I was wondering if maybe I got the wrong package version, then I posted here to get clarifications.

Unfortunately, we couldn't have this package working as expected, so we uninstalled this package shortly after.

Our latest attempts were made with a httpClient PostAsync, where "success" was returned but we didn't receive the test mail sent. Same happened with Postman request. Opened Mailjet support tickets but still waiting for additional clarification.

Reference guide: image

fabr2004 avatar Nov 29 '23 11:11 fabr2004

The Version property doesnt seem to exist, and the automagic usage of the API to use does not work as intended either, the example for @fabr2004 s screen will not compile here - however, sticking to API v3 seems to fix the issue... also, mails had no content when using HTMPPart - they get send and ewverything, but have no content :/

Sub account API key did not work for me as well and triggered an invalid sender warning with the API key instead of the sender address.

thomaswollburg avatar Jan 04 '24 06:01 thomaswollburg

I think this is very weird. Why isnt there any clarification or changes in the guide or code?

Flaflo avatar Feb 11 '24 01:02 Flaflo

Thanks for the clarification.

I was trying to implement Mailjet Dev guide (https://dev.mailjet.com/email/guides/send-api-v31/) to send transactional e-mails. The guide states (see below) to place Version = ApiVersion.V3_1 but this was not allowed, caused an error. We had <package id="Mailjet.Api" version="3.0.0" targetFramework="net48" />.

While investigating this I noticed Nuget package is described as "Official C# client library For Mailjet API version 3" and has "project URL" pointed here. So, since Mailjet informs latest e-mail API to be v3.1, I was wondering if maybe I got the wrong package version, then I posted here to get clarifications.

Unfortunately, we couldn't have this package working as expected, so we uninstalled this package shortly after.

Our latest attempts were made with a httpClient PostAsync, where "success" was returned but we didn't receive the test mail sent. Same happened with Postman request. Opened Mailjet support tickets but still waiting for additional clarification.

Reference guide: image

Same here, client returns 200 response, but email is not sent when using:

        var request = new MailjetRequest
        {
            Resource = Send.Resource,
        }
        .Property(Send.FromEmail, _emailConfiguration.SenderEmail)
        .Property(Send.Subject, subject)
        .Property(Send.TextPart, body)
        .Property(Send.HtmlPart, body)
        .Property(Send.Recipients, new JArray {
            new JObject {
                {"Email", toEmail}
                }
            });

        var response = await _mailJetClient.PostAsync(request);

amarkezic avatar Mar 12 '24 20:03 amarkezic

After digging through the source, I eventually got it working by doing the following:

var request = new MailjetRequest { Resource = SendV31.Resource }
        .Property(Mailjet.Client.Resources.Send.Messages, new JArray {
            new JObject {
                {"From", new JObject {
                    {"Email", "[email protected]"},
                    {"Name", "No-Reply Example"}
                }},
                {"To", new JArray {
                    new JObject {
                        {"Email", "[email protected]"},
                    }
                }},
                {"TemplateID", 2141221},
                {"TemplateLanguage", true},
                {"Subject", "Example"},
                {"Variables", new JObject {
                    {"name_first", "John Doe"}, 
                }}
            }
        });

var response = await _client.PostAsync(request);

Flaflo avatar Mar 13 '24 14:03 Flaflo

@Flaflo Thank you for that workaround, just confirmed that the following steps can fix the code from the MailJet documentation on sending on API version 3.1:

  1. Comment out the version code

var client = new MailjetClient(MarketingAPIKey, MarketingSecretKey) { //Version = ApiVersion.V3_1, };

  1. Modify Send.Resource to be SendV31.Resource

var request = new MailjetRequest { Resource = SendV31.Resource, }

ywingdriver avatar Mar 21 '24 21:03 ywingdriver

Thanks @Flaflo and @ywingdriver for having a solution for the issue.

I'm also wondering about sending emails in bulk https://dev.mailjet.com/email/guides/send-api-v31/#send-in-bulk after seeing the implementation for Mailjet.Client.Resources > SendV31 at https://github.com/mailjet/mailjet-apiv3-dotnet/blob/271c62bd7bc391e2ef16837d4318d98ada43496e/Mailjet.Client/Resources/SendV31.cs#L10 that does the MaxEmailsPerBatch mean that there is a limit of 50 emails per batch. Didn't find anything related to this limitation in the documentation but am going to implement utilizing the client with that limit and not trying to send more than 50 emails in one batch since the MaxEmailsPerBatch constant is public.

EDIT: it probably does so it is a good idea not to try to send more than 50 emails in a batch when using Api version 3.1: https://github.com/mailjet/mailjet-apiv3-dotnet/blob/271c62bd7bc391e2ef16837d4318d98ada43496e/Mailjet.Client/MailjetClient.cs#L141

juhaalhojoki avatar Apr 08 '24 10:04 juhaalhojoki

After digging through the source, I eventually got it working by doing the following:

var request = new MailjetRequest { Resource = SendV31.Resource }
        .Property(Mailjet.Client.Resources.Send.Messages, new JArray {
            new JObject {
                {"From", new JObject {
                    {"Email", "[email protected]"},
                    {"Name", "No-Reply Example"}
                }},
                {"To", new JArray {
                    new JObject {
                        {"Email", "[email protected]"},
                    }
                }},
                {"TemplateID", 2141221},
                {"TemplateLanguage", true},
                {"Subject", "Example"},
                {"Variables", new JObject {
                    {"name_first", "John Doe"}, 
                }}
            }
        });

var response = await _client.PostAsync(request);

You solved my problem,now I got the message

VictorZhong4475 avatar Sep 09 '24 06:09 VictorZhong4475