Closed buddhika85 closed 5 years ago
I'm seeing exactly the same problem in a WebForms app in addition to MVC. Even sub-classed Mailjet.Api into an external class within my app to see if that would help. Console apps work fine, but web-based just hangs. My code is a verbatim copy of the code in the Github project read.me for "Send Mail".
Message gets sent, but the response just hangs indefinitely.
@LeadMagnet , As a workaround I used code available on this GitHub repository to create contact lists.
https://github.com/AshleyMedway/MailJet.NET/blob/master/MailJetClient/MailJetClient.cs
Thanks for the suggestion, but this won't do for me. I've had all the dev's install Papercut to simulate email while testing. Started converting our email class into a web service to use standard IIS6 SMTP as that works just fine. Funny, even opening a case with MailJet for this issue got me nowhere.
I've got the same problem. (AshleyMedway/MailJet.NET does not work either)
Is there a solution ?
Thank
same here with web api
Finally I force sync mode, like that : Task.Run( () => Client.PostAsync(request) ).Wait();
Hello guys,
We'll try to address this. I'll keep you posted.
Regards, T.
I force it as @SybilBoquet but assign the task to a variable for evaluating the result.
var response = Task.Run(() => client.PostAsync(request));
response.Wait();
if (response.Result.IsSuccessStatusCode)...
Hi @buddhika85,
We reviewed your code example and everything seems good, could you please share with us what is the version of Dotnet that you are using? I just created a contact list from the web forms (with the name of the contact list "test contact list from web forms") using the following code : MailjetResponse response = null;
var client = new MailjetClient(key, secret);
MailjetRequest request = new MailjetRequest
{
Resource = Mailjet.Client.Resources.Contactslist.Resource,
}
.Property(Mailjet.Client.Resources.Contactslist.Name, "test contact list from web forms");
response = await client.PostAsync(request);
if (response.IsSuccessStatusCode)
{
result = string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount());
}
else
{
result = string.Format("ErrorInfo: {0}\n ErrorMessage: {1}\n", response.GetErrorInfo(), response.GetErrorMessage());
}
And it was correctly created. We tested with 4.6.1 and 4.5 of dotnet. Could you please also test the suggestion of @ChavaNava and @SybilBoquet ? I'll close the issue as a solution is proposed. Please feel free to open a new one, if needed.
Hi
After an additional review of the issue and a couple of tests, we found what may be the reason for your issues is that you are having a deadlock in your situation. Usually, if you try to call the asynchronous method in the synchronous method in ASP.NET MVC or ASP.NET Web Forms it may lead to this problem. It's a common issue and we suggest you to not use it .Wait() or .Result calls for you asynchronous methods ( CreateContactList().Wait(), CreateContactList().Result ). It's better to replace it with: var result = CreateContactList(); Please check out how you are calling asynchronous methods on your side and let us know if after our suggestion the issue persists.
Hi,
I have following code in a class library to to create a mailjet contact list.
`public async Task CreateContactList(string contactListName)
{
MailjetResponse response = null;
ResultMessage resultMessage = null;
try
{
var client = new MailjetClient(MjApikeyPublic, MjApikeyPrivate);
MailjetRequest request = new MailjetRequest
{
Resource = Contactslist.Resource,
}
.Property(Contactslist.Name, contactListName);
This works fine when I use it with a console application, and when debugged it hits the below line and gets http response from mailjet. And when I check it in the mailjet profile I can see the contact list with passed name is created at their end.
resultMessage = GetResultMessage(response, exception: null);
But when I used the same with a ASP.NET MVC application, it does not receive the http response, the application hangs forever. And when debugged it never reaches the above line. But, the list gets created in the mailjet end, so the only issue is it does not capture the http response from the mailjet.Can someone please help me?