shawnmclean / mandrill-dotnet Goto Github PK
View Code? Open in Web Editor NEW.NET wrapper for Mandrill
License: Other
.NET wrapper for Mandrill
License: Other
Hi, I was testing the capabilities of webhook.
If I have a Mandrill.WebHookEvent with e.Event = Mandrill.WebHookEventType.Click can i retrieve the property "url" ? I dont know how to retrieve WebHookClick from WebHookEvent.
If you could help me I would be really happy
Best Regards
Hi,
The property to
in mailmessage object expects a generic list of mandril email addresses List<Mandril.Emailaddress>
, which is basically a generic list of strings. Can you change this to generic list of strings?
Because i'll have to install the wrapper (which has dependencies) in another project too, just for the email addresses which I can perfectly put in a generic list.
Cannot successfully make any API calls to Mandrill. A "Post failed api/endpoint.json message is all the is given.
Here is example code that is generating the error:
MandrillApi api = new MandrillApi("xxxxx-xxxx-xxxx-xxxx");
UserInfo info = api.UserInfo();
Can anyone point me in the right direction?
Hi
I want to use this package inside Dotnetnuke. Problem is that the latest DNN is running with a much earlier version of NewtonSoft. Can anyone tell me if I can build this against Newtonsoft 4.5.7.15008.
thanks
Gus
Hi,
I facing issue in open mail tracking(read receipt).
I am using the below mention code for, but I am not getting the "open" event in the enum.
Mandrill.Info i = new Mandrill.Info(recipientTrackingId);
Mandrill.SearchResult result = client.Info("83c069844f3a43d293ac1a95230852b8");
foreach (var evnt in result.smtp_events)
{
if(evnt.type == Mandrill.SearchResultState.) // Here I am not getting the Open event
// Could you guide me how to do the same?
}
List of enum valus are as below.
Sent = 0,
Bounced = 1,
Rejected = 2,
SoftBounced = 3,
Spam = 4,
Unsub = 5,
Deferred = 6,
I am using mandrill dll version is 0.1.1.4.
Am I using old version of the Mandrill API?
Thanks in advance.
Regards,
Mahesh
Are there any plans to add support for the Messages Info Api method call?
https://mandrillapp.com/api/docs/messages.JSON.html#method=info
Recently my reject retrieval stopped working, I thought it might be a change in Json.Net but I noticed the response now includes index numbers (the docs still show it as a simple array). Haven't figured out how to fix this in the code but I thought it worth noting.
{
"0": {
"reason": "hard-bounce",
...
"sender": null
},
"1": {
"reason": "soft-bounce",
...
"sender": null
}
}
I want to unit test a class that uses MandrillApi. This is not possible because MandrillApi cannot be stubbed. It would be great if this class could be backed by an interface.
The signatures of the interface could also be cleaned up to remove the overloads. Extension methods on the interface could then provide the overload method functionality. This will make both the interface and MandrillApi class lean, clean and stubable while providing the same functionality :)
On class "EmailMessage" the "metadata" property is defined as a 'JsonObject' while the "recipient_metadata"'s property type "rcpt_metadata" has its values stored as an IEnumerable of strings. During JSON serialization, the "metadata" property becomes a Hash with key/value pairs while the "rcpt_metadata" property becomes an array. It would be much better if both of these objects are translated to the same type since they are related to each other and are handled together in Mandrill.
My suggestion is to change the struct rcpt_metadata and set the property "values" to the JSONObject type instead, i.e.
public struct rcpt_metadata
{
public string rcpt;
public JsonObject values;
}
and also imlement a method for adding new key value pairs to this struct.
What do you think of this suggestion?
Please sign the assembly with a strong-name certificate so that we don't have to fetch sourcecodes, integrate, and do it ourselves.
It would be cool if the NuGet package just worked, even for projects that have been strong signed.
Hi All,
Two days ago we had faced a connectivity problem to mandrillapp.com domain due to our ISS provider. This problem caused timeout exceptions and interrupted some parts of our systems which use Mandill
So now, i am trying to handle this situation to overcome any furher problems.
But i wonder what is the best way?
Regarding to our business, sending mail is important but not compulsory. So if it fails to send mail, system should continue to run without interrupt.
Does simply covering SendMessage method calls in try..catch block prevent this problem?
I have followed the instructions for the contributors and have created an account with mandrill, created a test template with empty content ('').
However when I run the tests, I see that the tests:
TemplatesTests.Can_Return_Individial_Template
and
TemplatesTests.Render_Template_Returns_Correct_Content
fail.
For the test TemplatesTests.Can_Return_Individial_Template
the error message is:
Test Name: Can_Return_Individial_Template
Test FullName: Mandrill.Tests.IntegrationTests.TemplatesTests.Can_Return_Individial_Template
Test Source: c:\Mandrill\tests\IntegrationTests\TemplatesTests.cs : line 50
Test Outcome: Failed
Test Duration: 0:00:00.747Result Message:
Expected: ""
But was: null
Result StackTrace: at Mandrill.Tests.IntegrationTests.TemplatesTests.Can_Return_Individial_Template() in c:\Mandrill\tests\IntegrationTests\TemplatesTests.cs:line 62
For the test TemplatesTests.Render_Template_Returns_Correct_Content
the error message is:
Test Name: Render_Template_Returns_Correct_Content
Test FullName: Mandrill.Tests.IntegrationTests.TemplatesTests.Render_Template_Returns_Correct_Content
Test Source: c:\Mandrill\tests\IntegrationTests\TemplatesTests.cs : line 28
Test Outcome: Failed
Test Duration: 0:00:00.648Result Message:
Expected string length 17 but was 0. Strings differ at index 0.
Expected: "Test"
But was: <string.Empty>
-----------^
Result StackTrace: at Mandrill.Tests.IntegrationTests.TemplatesTests.Render_Template_Returns_Correct_Content() in c:\Mandrill\tests\IntegrationTests\TemplatesTests.cs:line 45
What am I doing/configuring wrong?
There doesn't seem to be a way to set a timeout on the call to Mandrill. It also looks like it is not being set on the RestSharp client variable. The last time I looked the RestSharp default timeout was 0. Therefore, if the Mandrill server doesn't close the socket the socket will live for eternity.
I can get you a pull request for this fix if you want, just let me know.
There is an option in the docs (https://mandrillapp.com/api/docs/messages.JSON.html#method-send, and template) that allows you to disable the 'View Content' link on the Outbound dashboard for sensitive mails. It'd be great to get that into this library.
The field is view_content_link
.
It is not a big deal, but the Mandrill NuGet package 1.0.93 doesn't work with the new RestSharp package 105.0.0.
I get a build error and can't start my application, because Mandrill wants the RestSharp library 104.4.0. Even though the Mandrill NuGet package site states:
Dependencies
RestSharp (≥ 104.4.0)
Newtonsoft.Json (≥ 6.0.1)
But it should be something like this:
Dependencies
RestSharp (= 104.4.0)
Newtonsoft.Json (≥ 6.0.1)
I am trying to add some attachments to an email that is being sent using the mandrill api via a Mandrill-dotnet wrapper. I have tried a number of different things to try to successfully attach the file but to no avail.
Who can give me some examples please attach the file by using the mandrill dot-net
which version for Restsharp and NewtonJson dll use for Mandrill v0.0.07 ?
I see bcc_address, to and from properties, but no cc: property. Is there a way to add cc: address/display name pairs?
For the bcc_address property, does this support multiple email addresses (comma-separated)? Does is support display name (e.g., "Fred Flinstone [email protected]")?
Apologies for opening an issue, did not see a discussion forum. Thanks for writing the wrapper, dropped in with ease.
In my template i have created div as below:
to be able to replace username.
And in code i have set like this
TemplateContent objTemplate1 = new TemplateContent();
objTemplate1.Name="user_name";
objTemplate1.Content ="grishma";
But not able to replace username.
There is a method to return all templates. However, there is no method to fetch a single template.
The corresponding Mandrill endpoint is /templates/info.json with a request JSON of:
{
"key": "example key",
"name": "Example Template"
}
Mandrill supports its own "async"parameter (which is by default set to false) to force queuing of a message and immediate return.
To improve the throughput of Send/SendAsync, it would be useful to have this parameter accessible as a property in EmailMessage.
Hello,
I have an ASP.NET MVC 5 application where I need to send an HTML newsletter for about 80000 emails. I installed Mandrill-dotnet and I have a few questions:
Is it possible to use Mandrill templates and replace a few items on the template?
How would you send so many emails? Through the API correct?
Would you add the emails to the TO List? How many by send?
How do you take care of the failed sending? My idea would be:
Queue emails = new Queue();
for each block of 200 emails {
try {
send
remove the 200 emails from queue
} catch (Exception) {
log exception
}
}
Well, I am not sure the best way to do this?
Can you do this on an MVC action?
I suppose I can't because the thread cannot be alive for so much time or am I wrong?
How should I do this?
I appreciate if someone could advice me on out to do this with Mandrill-dotnet.
Thank You,
Miguel
In any of the SendMessage or SendMessageAsync methods, it seems that the default "send_at" parameter is not nullable and instead uses the default(DateTime) value, since DateTime variables that aren't nullable can't be null (they are instead DateTime.MinValue). This apparently results in a value being sent for the "send_at" parameter in the request that turns the transaction into a scheduled message, which I don't want because it is a pay feature. So even though I am not specifying the date purposely, it still thinks I am trying to schedule my message, which results in a "Email scheduling is only available for accounts with a positive balance" error (I am using a free account).
How to get state of email for a single message by id example "2fd2f3c2220d422d857e90a1dcc0eda0"
Would it be possible to update the latest nuget version? The version there is pretty old, and doesn't contain, for example, the Id field in EmailResult.
Setup auto-deploy to NuGet
https://mandrillapp.com/api/docs/rejects.JSON.html#method=delete
The method is missing an optional parameter to include a subaccount.
Want to be able to reuse templated regions in my templates (footer, header, rows etc).
Hello,
First of all thank you very much for creating this wrapper for the Mandrill API and C#. It's wonderful!
I'm trying to send an email that will include an embedded image. This is supported in the API from Mandrill, and images is a property available for the EmailMessage object in this wrapper.
However, I have been unsuccessful in creating the IEnumerable to pass into the EmailMessage.images property.
Does anyone have any advice?
Hi,
Why do I need to pass a senders email address if I use a template that already contains the senders email address? Take for example this code:
var emailMessage = new EmailMessage { from_email = "[email protected]", // <--- why is this required? text = api.Render(TEMPLATE, null, mergeVar).html, preserve_recipients = false, // false means recipients won't see other recipient email addresses; true will allow recipients to view and reply-all for all recipients. to = addresses, };
If i remove this line: from_email = "[email protected]",
, I get an error something about the email didn't got send because of invalid senders address (or something).
The following snippet from the API docs (https://mandrillapp.com/api/docs/messages.JSON.html#method-send) shows how nullable boolean fields can be used, or not used.
{
...
"important": false,
"track_opens": null,
"track_clicks": null,
"auto_text": null,
"auto_html": null,
"inline_css": null,
"url_strip_qs": null,
"preserve_recipients": null,
"view_content_link": null,
...
}
This is crucial for things like stripping out query string parameters for click tracking aggregation. The property url_strip_qs
on an message-level overrides the sending defaults defined within Mandrill.
Imagine your sending default was true
. By forgetting to explicitly set this property to true
or anything in .NET you unintentionally set it to false
(as the field on the model is a boolean with a default of false
), meaning you have to be sure to explicitly set these values in code, which defeats the purpose of global sending defaults - well, those that differ from the .Net default values.
TL;DR: The boolean fields in EmailMessage (and perhaps other models) should be nullable.
I require to strong name all the assemblies I reference in my project. Hence I have Mandrill and Restsharp both strongly named. But MandrillApi looks for RestSharp assembly which is not strong name. Hence it fails.
Following exception is thrown when I call MandrillApi constructor.
System.IO.FileLoadException was unhandled by user code
HResult=-2146234300
Message=Could not load file or assembly 'RestSharp, Version=104.4.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
Source=Mandrill
FileName=RestSharp, Version=104.4.0.0, Culture=neutral, PublicKeyToken=null
FusionLog=""
StackTrace:
at Mandrill.MandrillApi..ctor(String apiKey, Boolean useSsl, Int32 timeout)
at Shindigg.Services.Messaging.MandrillBackgroundWorkerMailProvider..ctor(IMessageService messageService, IMessageContentProvider messageContentProvider, ISmtpClient smtpTransactionalAccountClient) in D:\Projects\Shindig\main\Src\UltimateEvents\Shindigg.Services\Messaging\MandrillBackgroundWorkerMailProvider.cs:line 53
at BuildUp_Shindigg.Services.Messaging.MandrillBackgroundWorkerMailProvider(IBuilderContext )
at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
InnerException:
I'm getting the following error trying to instantiate the MandrillApi in an asp.net app.
e.g. var api = new MandrillApi("key");
Method 'Deserialize' in type 'Mandrill.Utilities.DynamicJsonDeserializer' from assembly 'Mandrill, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
I'm running .net v4.5 with Mandrill 0.1.1.0. I tried debugging but couldn't work out why the issue was happening. It looks like the method is implemented.
Track Opens and Track clicks have global settings which are set in the mandrill UI. I think what we need to do is change those to nullabel bools
bool? tracks_opens and do the same for any optional parameters that have global defaults.
In a VB.NET project, 'attachment' is ambiguous in the namespace 'Mandrill' because the identifiers of the class Mandrill.Attachment and the structure Mandrill.attachment differ only in case.
Hi All,
I'm considering using Mandrill in our application. I have looked at the implementation of PostAsync method and noticed that it uses blocking implementation of RestSharp.Execute. And the async implementation is commented out with comment CODEPATH IS DISABLED (USES EXECUTEASYNC). EXECUTE ASYNC HAS A BUG.
I think it is commented out since very first version in repository. I think that bug in RestSharp is fixed already. I have run all tests with RestSharp.ExecuteAsync and all tests passed as expected.
Should I create a pull-request with this fix for ExecuteAsync implementation or maybe someone is going to fix it?
Kind regards,
Andrii
I am having a issue while trying to send using SendTemplate if I am using AddRecipientVariable to set merge vars. I get "Post failed /messages/send-template.json".
The problem seems to be that "rcpt" in message.merge_vars is not set, it is always "Nothing".
Below code illustrate the problem:
Dim api As MandrillApi = New MandrillApi(CMandrilAPIKey)
Dim toMail As New List(Of Mandrill.EmailAddress)
Dim toAddress As Mandrill.EmailAddress
toAddress = New Mandrill.EmailAddress
toAddress.name = "R1"
toAddress.email = "[email protected]"
toMail.Add(toAddress)
Dim message As New Mandrill.EmailMessage
message.text = "Hello World!"
message.subject = "First Test Mail"
message.from_email = "[email protected]"
message.to = toMail
message.from_name = "From Name"
message.AddGlobalVariable("FNAME", "Default value")
message.AddRecipientVariable("[email protected]", "FNAME", "FirstName")
For Each l As Mandrill.rcpt_merge_var In message.merge_vars
Dim tst As String = l.rcpt
Next
Dim lContent As New List(Of Mandrill.TemplateContent)
Dim lResult As List(Of Mandrill.EmailResult) = api.SendTemplate(message, "Test001", lContent)
I have recently downloaded your library and had an issue when trying to add headers. The headers object has a private set and the type is JsonObject. For my usage I have changed the type to Dictionary<string,string> so I can use it like this:
using MC = Mandrill;
...
MC.EmailMessage mc_msg = new MC.EmailMessage();
...
mc_msg.headers = new Dictionary<string, string>();
mc_msg.headers.Add("Reply-To", ReplyToAddress);
In doing so I had to change the add headers method and the add metadata method after I changed it as well. I did not see the add headers method to start with, and actually I would rather set properties on the object than call the methods. This change would actually render the add headers and add metadata methods unnecessary, and might be a good practice to put throughout the library for these types of scenarios with an object with just a name and a value. I apologize in advance if there is anything about this that is not good practice as I do the best I can and this seems like a good way to handle this to me, rather than using the jsonobject types.
Below is a copy of the changes I have made in my local version of the library:
...
public Dictionary<string, string> headers { get; set; }
...
public Dictionary<string, string> metadata { get; set; }
public void AddHeader(string name, string value)
{
if (this.headers == null)
{
this.headers = new Dictionary<string, string>();
}
this.headers.Add(name, value);
}
public void AddMetadata(string key, string value)
{
if (this.metadata == null)
{
this.metadata = new Dictionary<string, string>();
}
this.metadata.Add(key, value);
}
How can I send merge_tags
using a template?
trying to send dynamic content to the template as merge_tags
from reading the docs.
but the Library specifies:
public List<EmailResult> SendMessage(EmailMessage message, string templateName, IEnumerable<TemplateContent> templateContents, DateTime send_at = null);
where TemplateContent
is a list of (almost) KeyValuePair
and if I'm passing:
List<TemplateContent> list = new List<TemplateContent>();
list.Add(new TemplateContent() { name = "*|CUSTOMER_NAME|*", content = "Bruno Alexandre" });
and pass the list
as templateContents
, I do not get the email to replace it.
I did try to use the mc:edit="customer_name"
and works fine, but I couldn't find out how to write inside an attribute link a link href
... works fine if I do:
<a href="#" mc:edit="customer_name">THIS WILL BE REPLACED</a>
but I wanted to change the link as well and doing this
<a href="*|CUSTOMER_LINK|*">*|CUSTOMER_NAME|*</a>
is not working...
what should I do?
inline_css
boolean
whether or not to automatically inline all CSS styles provided in the message HTML - only for HTML documents less than 256KB in size
I just updated to the latest version of the Mandrill NuGet package and got compiler errors because stuff like attachment
was renamed to email_attachment
. Since NuGet versioning is based on semantic versioning, such a change should incur a major version change, i.e. from 1.0
to 2.0
. If you want to simplify the process of versioning the package, I can recommend following git-flow or github-flow and adding GitVersionTask to the projects that need versioning.
If you want help with that, please let me know.
Hi,
All the API calls that I am using are working except the .Info part. I have tried my Key and ID on the Mandrill API test site and it comes back fine. The message I am getting is Unable to parse JSON. I can see the JSON in the result but not getting any further and thus there is just nulls in the SearchResult. Has the API changed or have you seen this before? I am using version 1.0.75 which I believe is the latest version.
Any help would be appreciated and thanks for putting the effort in to making a great wrapper.
Here is the code I am using:
MandrillApi api = new MandrillApi("MY-KEY");
Info oMessageInfo = new Info();
oMessageInfo.id = "ID";
SearchResult oSearchResult = api.Info(oMessageInfo);
Many Thanks
Ben
Update : solved
It looks like this may be an issue with how Mandrill-dotnet's Nuget package is managing certain assemblies?
I installed the Mandrill API package, and now whenever calling the followin g code:
var mandrill = new MandrillApi(MANDRILL_API_KEY);
I receive the following error:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in [MyAppName].exe
Additional information: Could not load file or assembly 'RestSharp, Version=104.4.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
I installed the package by running Install-Package Mandrill
and I have successfully used it before, which has be a little confused.
When installing the Nuget package, it appears to resolve references as normal:
install-package mandrill
Attempting to resolve dependency 'RestSharp (≥ 104.4.0)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.1)'.
'Mandrill 1.0.85' already installed.
Adding 'Mandrill 1.0.85' to MassEmailUtility.Core.Tests.
Successfully added 'Mandrill 1.0.85' to MassEmailUtility.Core.Tests.
And indeed, inside my packages.config for the projects, I see:
<package id="Mandrill" version="1.0.85" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
<package id="RestSharp" version="104.4.0" targetFramework="net45" />
Any suggestions on how I might remedy this? It's a new one for me.
Hello,
I being a project in which we will need to use the WebHooks available in Mandrill to notify our application in the event that that an email message is bounced (hard or soft).
Setting up the WebHook in Mandrill is simple enough, and I see that there is a WebHookEvent.cs file in the Mandrill-dotnet repo.
Are there any examples illustrating how to get started consuming a WebHook from the Mandrill with Mandrill-dotnet?
Hi,
I need to be able to process inbound mails, and based on this link http://help.mandrill.com/entries/21699367-Inbound-Email-Processing-Overview, I have to create a webhook with a corresponding public url. In terms of implementing the action method, I followed the method signature as described in the documentation of WebHookEvent.cs (https://github.com/shawnmclean/Mandrill-dotnet/blob/master/src/Mandrill/Models/WebHookEvent.cs). At that point everything was working as expected: if I send mail to the mandrill email which I registered to the webhook event, the action method is invoked from Mandrill. For discussions's sake let's assume that the method name is ProcessInboundMail.
Moving forward, my app needs to support multitenancy. So instead of a straightforward processing in the method ProcessInboundMail, I have to somehow Redirect to a url that includes the appropriate subdomain (e.g. company1.myapp.com/mycontroller/ProcessInboundMail). From then on I started to encounter a peculiar issue.
If I send mail to the mandrill email, the action method is no longer properly executed. To verify if the webhook is working, I went to the mandrill admin page > Inbound > Domains (InboundDomains.png), clicked Routes button, then clicked the button "send test" (MailboxRoutes.png), but all I get is this error message:
Webhook failed with error: POST to http://myapp.com/mycontroller/ProcessInboundMail failed with 411: Length Required
Length Required
HTTP Error 411. The request must be chunked or have a content length.
Here is how my ProcessInboundMail looks like:
[AllowAnonymous]
[ValidateInput(false)] // May be required if accepting inbound webhooks, http://msdn.microsoft.com/en-us/library/hh882339.aspx
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post | HttpVerbs.Head)]
public ActionResult ProcessInboundMail(string id, FormCollection val)
{
var events = Mandrill.JSON.Parse<List<Mandrill.WebHookEvent>>(val.Get("mandrill_events"));
foreach (var e in events)
{
...
var redirectResult = Redirect(toSomeUrl);
redirectResult.ExecuteResult(this.ControllerContext);
}
return Json(1, JsonRequestBehavior.AllowGet);
}
My question is, how come when I was not using Redirect, clicking "send test" was successful, but now that I am using Redirect, I'm getting this HTTP error 411 when clicking "send test"? What am I doing wrong here?
user_agent
user_agent_parsed
ip
location
Are all missing from the WebHookEvent class. Also, Url should be duplicated in the WebHookEvent class, currently it only resides in the WebHookClick class.
Does this API give me access to the email message response code i.e. Delivered, Bounced, Spam, Opened, Clicked, etc?
Is it possible to add support so that merge vars can be sent using "SendMessage" instead of or in addition to, "TemplateContent"? I only have one basic merge var in the template
|CODE| and I can't seem to update it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.