working on it ...

Filters

Explore Public Snippets

Sort by

Found 36 snippets

    public by cghersi @ MailUp API DEV modified Aug 29, 2018  1675  46  5  0

    MailUp REST API - How to send a transactional email message

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server. The credentials of the SMTP+ user are passed as parameter in the body of the request. Explore the MessageDTO object in order to understand how you can customize the message you want to send.
    public static void SendMessage()
    {
      // 1) Required values
      string username = "<your_username>";
    	string password = "<your_password>";
    
    	string clientid = "<your_clientid>";
    	string clientsecret = "<your_clientsecret>";
    
    	string smtpplus_username = "<your_smtpplus_username>";
    	string smtpplus_password = "<your_smtpplus_password>";
      
      // 2) Setup the MailUp Client:
    	MailUpClient client = new MailUpClient(clientid, clientsecret);
    	client.RetrieveAccessToken( username, password );
    
      // 3) prepare the input:
      MessageDTO msg = new MessageDTO()
      {
        Html = new HtmlDTO()
        {
          Body = "<div>Hello Mr. [firstname][lastname] !!!</div><br><img width='600' height='397' src='cid:img001'>",
          BodyTag = "<body>"
        },
        Text = "Hello world!!!",
        Subject = "Hello friend!",
        From = new EmailAddressDTO() { Name = "Test User", Email = "test@mailup.it" },
        To = new List<EmailAddressDTO>() { new EmailAddressDTO() { Name = "Massimo", Email = "info@mailup.it" } },
        Cc = new List<EmailAddressDTO>(),
        Bcc = new List<EmailAddressDTO>(),
        ReplyTo = null,
        CharSet = "utf-8",
        ExtendedHeaders = null,
        Attachments = null,
        EmbeddedImages = new List<MessagePartDTO>() {
          new MessagePartDTO() {
            Filename = "Image.jpg",
            ContentId = "img001",
            Body = new byte[] { 0x01, 0x02, 0x03, 0x04 }
          }
        },
        XSmtpAPI = new XSmtpAPIDTO()
        {
          CampaignName = "Test Campaign",
          CampaignCode = "1001",
          Header = null,
          Footer = null,
          ClickTracking = null,
          ViewTracking = null,
          Priority = null,
          Schedule = null,
          DynamicFields = new List<NameValueDTO>() {
            new NameValueDTO() { N = "firstname", V = "Mario"},
            new NameValueDTO() { N = "lastname", V = "Rossi"}
          },
          CampaignReport = null,
          SkipDynamicFields = null
        },
        User = new SmtpUserDTO() { Username = smtpplus_username, Secret = smtpplus_password }
      };
    
      // 4) Invoke the web method:
      SendResponseDTO result = null;
      try
      {
        result = client.SendMessage(msg);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Cannot perform the operation due to " + ex.Message);
        return;
      }
    
      // 5) Print results:
      if (result != null)
        Console.WriteLine("Result of sending task:" + result.Message);
      else
        Console.WriteLine("An error occurred while sending message.");
    }
    						

    public by cghersi @ MailUp API DEV modified Aug 29, 2018  2232  12  5  0

    MailUp REST API - How to send a transactional email message that follows a template

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server. The credentials of the SMTP+ user are passed as parameter in the body of the request. Explore the TemplateDTO object in order to understand how you can customize the message you want to send.
    public static void SendTemplate()
    {
      // 1) Required values
      string username = "<your_username>";
    	string password = "<your_password>";
    
    	string clientid = "<your_clientid>";
    	string clientsecret = "<your_clientsecret>";
    
    	string smtpplus_username = "<your_smtpplus_username>";
    	string smtpplus_password = "<your_smtpplus_password>";
      
      // 2) Setup the MailUp Client:
    	MailUpClient client = new MailUpClient(clientid, clientsecret);
    	client.RetrieveAccessToken( username, password );
    
      // 3) prepare the input:
      TemplateDTO msg = new TemplateDTO()
      {
        TemplateId = 694,
        Subject = "Test message from template",
        From = new EmailAddressDTO() { Name = "Test User", Email = "test@mailup.it" },
        To = new List<EmailAddressDTO>() { new EmailAddressDTO() { Name = "Massimo", Email = "info@mailup.it" } },
        Cc = new List<EmailAddressDTO>(),
        Bcc = new List<EmailAddressDTO>(),
        ReplyTo = null,
        CharSet = "utf-8",
        ExtendedHeaders = null,
        Attachments = null,
        EmbeddedImages = new List<MessagePartDTO>() {
          new MessagePartDTO() {
            Filename = "Image.jpg",
            ContentId = "img001",
            Body = new byte[] { 0x01, 0x02, 0x03, 0x04 }
          }
        },
        XSmtpAPI = null,
        User = new SmtpUserDTO() { Username = smtpplus_username, Secret = smtpplus_password }
      };
    
      // 4) Invoke the web method:
      SendResponseDTO result = null;
      try
      {
        result = client.SendTemplate(msg);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Cannot perform the operation due to " + ex.Message);
        return;
      }
    
      // 5) Print results:
      if (result != null)
        Console.WriteLine("Result of sending task:" + result.Message);
      else
        Console.WriteLine("An error occurred while sending template.");
    }
    												

    public by cghersi @ MailUp API DEV modified Aug 29, 2018  1750  8  5  0

    MailUp REST API - How to retrieve information of SMTP+ Users

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server. The credentials of the SMTP+ user are passed as parameter in the body of the request. You can optionally specify a username as third parameter in order to filter the resulting list.
    public static void GetUserInfo()
    {
      // 1) Required values
      string username = "<your_username>";
    	string password = "<your_password>";
    
    	string clientid = "<your_clientid>";
    	string clientsecret = "<your_clientsecret>";
    
    	string smtpplus_username = "<your_smtpplus_username>";
    	string smtpplus_password = "<your_smtpplus_password>";
      
      // 2) Setup the MailUp Client:
    	MailUpClient client = new MailUpClient(clientid, clientsecret);
    	client.RetrieveAccessToken( username, password );
    
      // 3) Invoke the web method:
      List<UserInfoDTO> result = null;
      try
      {
        result = client.ListUserInfo(smtpplus_username, smtpplus_password);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Cannot perform the operation due to " + ex.Message);
        return;
      }
    
      // 4) Print results:
      if (result != null)
        Console.WriteLine("Retrieved users total:" + result.Count);
      else
        Console.WriteLine("An error occurred while retrieving users.");
    }
    																		

    public by cghersi @ MailUp API DEV modified Jan 20, 2015  206772  8  6  1

    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 MailU
    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!");
    }
                

    public by cghersi @ MailUp API DEV modified Jan 20, 2015  1516  15  6  0

    MailUp REST API - How to subscribe a single contact 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 MailU
    public static void SubscribeContactWithCOI(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) Prepare the input:
      int idList = 1;
      ConsoleRecipientItem recipient = new ConsoleRecipientItem()
      {
        Email = "test1COI@mailup.com",
        Name = "First COI New Recipient" + DateTime.Now.ToFileTimeUtc(),
        Fields = new List<ConsoleRecipientDynamicFieldItem>()
        {
            new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name1COI_" + DateTime.Now.ToFileTimeUtc() },
            new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName1COI_" + DateTime.Now.ToFileTimeUtc() }
            //here you can add all the fields you want to add...
        }
      };
    
      // 3) Invoke the web method:
      int result = 0;
      try
      {
        result = client.AddRecipientToList(idList, recipient, true);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Cannot perform the operation due to " + ex.Message);
        return;
      }
    
      // 4) Print results:
      if (result > 0)
        Console.WriteLine("Recipients Added with confirmed Opt-in! The ID of the recipient is " + result);
      else
        Console.WriteLine("An error occurred while adding the recipients with confirmed Opt-in.");
    }
                

    public by cghersi @ MailUp API DEV modified Jan 20, 2015  1862  18  5  0

    MailUp REST API - How to authenticate with 3 leg process flow

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 3 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 MailUpC
    @using MailUp.Sdk.Base
    @using MailUp.Framework.Contracts.API.Base
    @using MailUp.Framework.Contracts.API.DataContracts.Console
    
    @{  
        Layout = "~/_SiteLayout.cshtml";
        Page.Title = "Welcome to the sample client to interact with MailUp REST API";
        
        MailUpClient mailUp = Session["MailUpClient"] as MailUpClient;
        string receivedCode = Request["code"];
        string redirUri = string.Empty;
        string accessTokenRetrieval = "Your application has been granted. You are now able to consume MailUp API!";
        if (string.IsNullOrEmpty(receivedCode))
        {
            // Phase 1: the authorization flow should be started with the redirection towards MailUp login form
            redirUri = mailUp.GetLogOnUri(Request.Url.AbsoluteUri);
        }
        else
        {
            // Phase 2: the MailUp login form redirected the user back to this page, with the code to be exchanged
            // with access token to securely consume REST API:
            try
            {
                mailUp.RetrieveAccessToken(receivedCode);
                
                //invoke a sample API:
                CollectionOf<ConsoleListItem> lists = mailUp.GetLists("", "idList ASC", 1);
                if ((lists != null) && (lists.Count > 0))
                {
                    accessTokenRetrieval += " E.g. your first list is named '" + lists[0].Name + "'";
                }
            }
            catch (MailUpException ex)
            {
                accessTokenRetrieval = "Unable to access the service due to " + ex.Message;
            }
        }
    }
    <p>
        Click here to start the authorization process. <br />
        The MailUp login page will be displayed and you will be able to enter your username and password. <br />
        Then, you will be redirected back here, with a valid access token that can be used to perform all the REST calls. <br />
        <br />
        @if (string.IsNullOrEmpty(receivedCode))
        {
            <input id="authFlowBtn" type="button" value="Login" onclick="javascript:document.location='@redirUri';" />
        }
        else
        {
            <text>@accessTokenRetrieval</text>
        }
    </p>            

    public by cghersi @ MailUp API DEV modified Jan 15, 2015  1988  19  6  0

    MailUp REST API - How to create and send an SMS to a specific recipient.

    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 MailU
    public static void CreateAndSendSMS(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) Create the message:
        int idList = 1;
        string subject = "Test Creation Sms";
        ConsoleSmsMessageDetailItem message = new ConsoleSmsMessageDetailItem()
        {
            Content = "Test Content",
            idList = idList,
            IsUnicode = false,
            Notes = "Bunch of test notes",
            Sender = "+390123456789",
            Subject = subject
        };
        ConsoleMessageItem createMsgResult = null;
        try
        {
            createMsgResult = client.CreateSmsMessage(idList, message);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Unable to create the message due to " + ex.Message);
            return;
        }
        if (createMsgResult == null)
        {
            Console.WriteLine("Unable to create the message");
            return;
        }
    
        // 3) Send the just created message:
        SmsSendToRecipientRequest request = new SmsSendToRecipientRequest()
        {
            Number = "3331234567",
            Prefix = 39,
            idMessage = createMsgResult.idMessage.Value
        };
        SmsMessageSendResponse result = null;
        try
        {
            result = client.SendSmsMessage(request);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        if (result != null)
            Console.WriteLine("Message sent to " + result.Sent + " recipient(s).");
        else
            Console.WriteLine("An error occurred while sending the message.");
    }
    

    public by cghersi @ MailUp API DEV modified Jan 15, 2015  1865  27  6  1

    MailUp REST API - How to create and send an email to a specific recipient.

    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 MailU
    public static void CreateAndSendEmail(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) Create the message:
        int idList = 1;
        string subject = "Test Creation Email";
        ConsoleMessageDetailItem message = new ConsoleMessageDetailItem()
        {
            Content = "Test Content",
            Embed = false,
            idList = idList,
            IsConfirmation = false,
            Notes = "Bunch of test notes",
            Subject = subject,
            TrackingInfo = new ConsoleEmailTrackingInfo() { Enabled = true, Protocols = new List<string>() { "http" } }
        };
        ConsoleMessageItem createMsgResult = null;
        try
        {
            createMsgResult = client.CreateMessage(idList, message);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Unable to create the message due to " + ex.Message);
            return;
        }
        if (createMsgResult == null)
        {
            Console.WriteLine("Unable to create the message");
            return;
        }
    
        // 3) Send the just created message:
        EmailSendToRecipientRequest request = new EmailSendToRecipientRequest()
        {
            Email = "recipient@mailup.com",
            idMessage = createMsgResult.idMessage.Value
        };
        MailMessageSendResponse result = null;
        try
        {
            result = client.SendEmailMessage(request);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        if (result != null)
            Console.WriteLine("Message sent to " + result.Sent + " recipient(s).");
        else
            Console.WriteLine("An error occurred while sending the message.");
    }
    

    public by cghersi @ MailUp API DEV modified Jan 15, 2015  1254  25  7  0

    MailUp REST API - How to subscribe to a particular list several contacts with some information like email, mobile number, etc.

    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 MailU
    public static void SubcribeRecipients(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) Prepare the input:
        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);
    
        // 3) Invoke the web method:
        int result = 0;
        try
        {
            result = client.AddRecipientsToList(idList, recipients);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        if (result > 0)
        {
            Console.WriteLine("Recipients Import started; import ID:" + result);
    
            //optionally we can check the import status:
            bool completed = false;
            do
            {
                ConsoleImportStatus importStatus = client.CheckImportStatus(result);
                if (importStatus == null)
                {
                    Console.WriteLine("Cannot check the import status for import task #" + result);
                    return;
                }
                completed = importStatus.Completed;
            } while (!completed);
            Console.WriteLine("Recipients Added!");
        }
        else
            Console.WriteLine("An error occurred while adding the recipients.");
    }
    

    public by cghersi @ MailUp API DEV modified Nov 19, 2014  1329  3  5  0

    How to Remove a recipient from a group of recipients with MailUp .NET SDK

    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 MailU
    public static void RemoveRecipientFromGroup(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) Prepare the input:
        int idGroup = 1;
        int idRecipient = 1;
    
        // 3) Invoke the web method:
        try
        {
            client.RemoveRecipientFromGroup(idGroup, idRecipient);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        Console.WriteLine("Recipient removed.");
    }
    
    • Public Snippets
    • Channels Snippets