mailjet / mailjet-apiv3-dotnet

[API v3] Official Mailjet API v3 .NET wrapper
https://dev.mailjet.com
MIT License
76 stars 32 forks source link

Variables not working with TransactionalEmailBuilder #78

Closed carjimfa closed 1 year ago

carjimfa commented 3 years ago

Hello community,

We are sending transactional emails using this library and recently started using templates instead of plain HTML. We have created a few templates in Mailjet but we are unable to set the variables properly. We are using TransactionalEmailBuilder like this:

var email = new TransactionalEmailBuilder();
var sendContacts = dto.Recipients.Select(s => new SendContact(s.EmailAddress, s.DisplayName));
email.WithTo(sendContacts);
email.WithSubject(dto.Subject);
email.WithFrom(new SendContact(dto.From, dto.FromName));
email.WithVariable("CurrentYear", "2021");
email.WithTemplateId(dto.MailjetTemplateId.Value);
return await Post(email.Build());

But when sending, the footer looks like this:

Screenshot 2021-07-01 at 12 57 39

I don't know but I'm trying to use this new feature because I was getting the same error as in issue 70 when sending with JObject and mostly the code provided when setting up a new template:

"StatusCode": 400, "ErrorInfo": "At least FromEmail or Sender must be provided"

We are using Mailjet library v 2.0.2 so the client now decides which API version to use so not much more to say about the error (there isn't one actually, just the result is not the expected).

We are using .Net Core 2.2.

Is someone else having problems with this builder? Is there a workaround? Are we doing something wrong?

Thanks in advance.

sdiakovskyi-gd commented 3 years ago

Hello @carjimfa, thanks for raising this issue!

to use template template variables, parameter TemplateLanguage should be set to true. From the documentation When true, activates the template language processing. Default value: false

this can be done with such code:

            email.WithTemplateLanguage(true);

Anyway, I think it makes a sense to set this parameter by default to true in SendTransactionalEmailsAsync if any variables are passed, to make the usage easier.

laurentAstonIf commented 3 years ago

Hi I have the same exact problem as carjimfa I'm converting our call done with v1.2.2 to 2.0.2 ( i can't find any doc on breaking change between v1 and v2 )

We were using Post(MailjetRequest) and some nodes keys have changed so i have tried to update ex : from => fromEmail and FromName => the emails are sent but all users put in cc and bcc are ignored I using Mailjet.Client.Resources.Send constants so i don"t understand how i can badly set these keys for cc and bcc

So i have decided to move to TransactionalEmail Everything work well (to, cc, bcc) except for the feature of templateId When i'm setting WithTemplateLanguage(true) image and if i set it to false the email is received but without any replacement of vars

Any idea ?

this is the language set in this template image

dmytrosvystun88 commented 1 year ago

Hello, I couldn't reproduce the issue. Transactional email is sent successfully with Français language and all variables are replaced.

If the issue still persists please post more details such as a sample code that creates a request and an example of a template.

dmytrosvystun88 commented 1 year ago

This is closed due to inactivity. Feel free to re-open in case of need.