Problem with To array for Recipients

Jul 15, 2012 at 12:36 AM

I am implementing the Mandrill API in VB.NET.

Setting all the string values for a message works just fine.

However, I can't for the life of me figure out how to set the recipients properly (or other array properties)

This code sets the Recipient name and email and I can read them - but the To: message property does not like this data type.

Dim rcp As New MailChimp.Types.Mandrill.Messages.Recipient("charles@123.com", "Charles Emerson")        

Dim message As New MailChimp.Types.Mandrill.Messages.Message

I tried also with a generic list, but...

Dim aRecipients As New Dictionary(Of String, String) From {{"email", "charles@123.com"}, {"name", "Charles Emerson"}}        

message.To = aRecipients

I set the string type to MailChimp.Types.Mandrill.Messages.Recipient - but still no dice

I have tried arrays and JSON as well - but it does not like the data types or format :-(

Dim aRecipients As New List(Of Dictionary(Of MailChimp.Types.Mandrill.Messages.Recipient, String))()        

aRecipients.Add(New Dictionary(Of MailChimp.Types.Mandrill.Messages.Recipient, String)() From { {New MailChimp.Types.Mandrill.Messages.Recipient("charles@123.com", "Charles Emerson"), "charles@123.com"}'})

I'm sure it's simple once it works - but I could really use an example :-D

Thanks!

Coordinator
Jul 23, 2012 at 8:45 PM

It is IEnumerable(Of Recipient). Try this:

Dim msg = New Mandrill.Messages.Message()
msg.To = New Mandrill.Messages.Recipient() {
   New Mandrill.Messages.Recipient("1@x.com", "1"),
   New Mandrill.Messages.Recipient("2@x.com", "2")
}

 

 

Jul 23, 2012 at 8:57 PM
I actually got it working this way:

Could use a bit of refactoring - but it has examples of all the needed template & message items :-)

Public Function TestMandrill() As String
Dim strResponse As String = ""
Dim apikey As String = "_API_KEY_"
Dim strTemplateName As String = "Example Email Template"
'Array of Recipients (should refactor to n recipients loop)
Dim recipient As New MailChimp.Types.Mandrill.Messages.Recipient("name@email.com", "Joe User")
Dim recipient1 As New MailChimp.Types.Mandrill.Messages.Recipient("name2@gmail.com", "Jane User")
Dim aRecipients(1) As MailChimp.Types.Mandrill.Messages.Recipient
aRecipients(0) = recipient
aRecipients(1) = recipient1
'Array of Tags
Dim strTags As String = "Lead|From Detail"
Dim aTags() As String = strTags.Split("|")
'Array of Google Analytics Domains
Dim strGoogleDomains As String = "domain.com|"
Dim aGoogleDomains() As String = strGoogleDomains.Split("|")
'Dim sEmailHeaders As New Dictionary(Of String, String) From {{"X-MC-Template", "body_content00"}}
Dim strFromEmail As String = "email@sample.com"
Dim strFromName As String = "CRM Admin"
Dim strSubject As String = "Testing Mandrill Email API"
Dim strText As String = "Test Mandrill Email"
Dim strHtml As String = "

Test Mandrill Email

"
'Array of Template Content Name Content Pairs
Dim templateContent As New MailChimp.Types.Mandrill.NameContentPair(Of String)("body_content00", strHtml)
Dim aTemplateContent(0) As MailChimp.Types.Mandrill.NameContentPair(Of String)
aTemplateContent(0) = templateContent
Try
Dim mc As New MailChimp.MandrillApi(apikey)
'Dim ok As String = mc.Ping
'strResponse = ok.ToString
Dim message As New MailChimp.Types.Mandrill.Messages.Message
Dim result As New MailChimp.Types.MVList(Of MailChimp.Types.Mandrill.Messages.SendResult)
With message
'.Headers = sEmailHeaders
.FromEmail = strFromEmail
.FromName = strFromName
.To = aRecipients
.Subject = strSubject
.Text = strText
.Html = strHtml
.Tags = aTags
.GoogleAnalyticsDomains = aGoogleDomains
End With
'result = mc.Send(message)
result = mc.SendTemplate(strTemplateName, aTemplateContent, message)
Catch ex As MailChimp.Types.MCException
strResponse = ex.Message
End Try
Return strResponse
End Function

Thanks,

Charles Emerson
www.FirstFreight.com

On Mon, Jul 23, 2012 at 1:45 PM, denisk1981 <notifications@codeplex.com> wrote:

From: denisk1981

It is IEnumerable(Of Recipient). Try this:

Dim msg = New Mandrill.Messages.Message()
msg.To = New Mandrill.Messages.Recipient() {
   New Mandrill.Messages.Recipient("1@x.com", "1"),
   New Mandrill.Messages.Recipient("2@x.com", "2")
}

Read the full discussion online.

To add a post to this discussion, reply to this email (mcapinet@discussions.codeplex.com)

To start a new discussion for this project, email mcapinet@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com