by
1
6
207k
8
Top 1% !
Pearl of Wisdom
Easy-to-find
Specified
Tuned
OpenSource
Popularity: 7682nd place

Published on:

AreaCommonUseCases
Extension.cs
InputName0clientID
InputName1clientSecret
InputName2username
InputName3password
InputType0string
InputType1string
InputType2string
InputType3string
LanguageCSharp
Languagegradle
LicenseMIT_X11
MethodNameSubcribeRecipientsWithDoubleOptin
OSWindows
OutputTypevoid

MailUp REST API - How to subscribe to a particular list several contacts with the "Confirmed Optin" Procedure

This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 two leg authentication.
You can start digging into the MailUP API world by reading this content: http://help.mailup.com/display/mailupapi/REST+API
An instance of MailUpClient class is able to manage one user at a time. 
A MailUpClient object needs a pair clientID-clientSecret, which you can retrieve following this procedure: http://help.mailup.com/display/mailupapi/Authenticating+with+OAuth+v2
Then, you should login with your credentials, invoking RetrieveAccessToken(username, password) method (it should be done just only once at the beginning of the process)
Finally, you can call all the methods you want! 
E.g. the subscription of multiple contacts with confirmed optin puts the contacts in a pending status, and sends an email to them with an activation link. After following this link, each contact is finally active.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/300492/MailUp-REST-API---How-to-subscribe-to-a-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static void SubcribeRecipientsWithDoubleOptin(string clientID, string clientSecret, string username, string password) { // 1) Setup the MailUp Client: MailUpClient client = new MailUpClient(clientID, clientSecret); try { client.RetrieveAccessToken(username, password); } catch (MailUpException ex) { Console.WriteLine("Unable to access the service due to " + ex.Message); return; } // 2) Subscribe recipients: int idList = 1; List<ConsoleRecipientItem> recipients = new List<ConsoleRecipientItem>(); ConsoleRecipientItem recipient1 = new ConsoleRecipientItem() { Email = "test1@mailup.com", Name = "First New Recipient" + DateTime.Now.ToFileTimeUtc(), MobileNumber = "3331234567", MobilePrefix = "39", Fields = new List<ConsoleRecipientDynamicFieldItem>() { new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name1_" + DateTime.Now.ToFileTimeUtc() }, new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName1_" + DateTime.Now.ToFileTimeUtc() } //here you can add all the fields you want to add... } }; ConsoleRecipientItem recipient2 = new ConsoleRecipientItem() { Email = "test2@mailup.com", Name = "Second New Recipient" + DateTime.Now.ToFileTimeUtc(), MobileNumber = "3337654321", MobilePrefix = "39", Fields = new List<ConsoleRecipientDynamicFieldItem>() { new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name2_" + DateTime.Now.ToFileTimeUtc() }, new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName2_" + DateTime.Now.ToFileTimeUtc() } //here you can add all the fields you want to add... } }; recipients.Add(recipient1); recipients.Add(recipient2); int subscriptionResult = 0; try { subscriptionResult = client.AddRecipientsToList(idList, recipients, true); } catch (Exception ex) { Console.WriteLine("Cannot perform the operation due to " + ex.Message); return; } // 2.1) wait for the end of import task: if (subscriptionResult > 0) { Console.WriteLine("Recipients Import started; import ID:" + subscriptionResult); //optionally we can check the import status: bool completed = false; do { ConsoleImportStatus importStatus = client.CheckImportStatus(subscriptionResult); if (importStatus == null) { Console.WriteLine("Cannot check the import status for import task #" + subscriptionResult); return; } completed = importStatus.Completed; } while (!completed); Console.WriteLine("Recipients Added!"); } else { Console.WriteLine("An error occurred while adding the recipients."); return; } // 3) Retrieve the sendingID of the confirmation email related to the previous task: int sendingID = -1; try { sendingID = client.GetSendingIDForImport(subscriptionResult); } catch (Exception ex) { Console.WriteLine("Cannot retrieve sending ID due to " + ex.Message); return; } if (sendingID <= 0) { Console.WriteLine("Cannot retrieve sending ID."); return; } // 4) Send the confirmation email: EmailSendingItem sendingResult = null; try { sendingResult = client.SendEmailMessage(sendingID); } catch (Exception ex) { Console.WriteLine("Cannot send email due to " + ex.Message); return; } if (sendingResult == null) Console.WriteLine("Cannot send confirmation email."); else Console.WriteLine("Confirmation email sent!"); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus