working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,324 snippets matching: subscribe

    public by cghersi @ MailUp API DEV  206862  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  69248  7  5  0

    How to Add a recipient to 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 AddRecipientToGroup(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;
        ConsoleRecipientItem recipient = new ConsoleRecipientItem()
        {
            Email = "testGroup@mailup.com",
            Name = "Group - New Recipient" + DateTime.Now.ToFileTimeUtc(),
            Fields = new List<ConsoleRecipientDynamicFieldItem>()
            {
                new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "NameGroup" + DateTime.Now.ToFileTimeUtc() },
                new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastNameGroup" + 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.AddRecipientToGroup(idGroup, recipient);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        if (result > 0)
            Console.WriteLine("Recipient Added!");
        else
            Console.WriteLine("An error occurred while adding the recipient.");
    }
    

    public by cghersi @ MailUp API DEV  1325  26  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  1595  16  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 mprisznyak  3364  2  6  3

    Hybrid publish-subscribe messaging

    a toy example with media publishers, media channels and viewers
    """
    A somewhat non-trivial toy example for the publish-subscribe messaging pattern
    It demonstrates  hybrid message filtering which combines a topic-based approach  with a content-based one
    Message production and publication are decoupled.
    
    MediaPublishers create Programmes for Channels and the publish these there.
    Customers subscribe for programmes they are interested in but the Channels 
    also enforce age limit restrictions on these subscribers when they notify them.
    
    """
    
    from random import choice, randint
    
    class Topics(object):
        """
        enumerate programme topics
        """
        SCIFI = "sci-fi films"
        ACTION = "action films"
        FAMILY = "family films"
        ROMANCE = "romantic films and soap operas"
        CARTOON = "cartoons"
        FOOTBALL = "football programmes"
    
        @classmethod
        def all_topics(klass):
            return [getattr(klass, attr) for attr  in klass.__dict__ if attr == attr.upper()]
    
    
    class Programme(object):
        """
        these are messages produced by MediaPublishers and received by Customers from Channels
        """
    
        def __init__(self, topic, description, age_limit, publisher_name):
            self.topic = topic
            self.description = description
            self.age_limit = age_limit
            self.publisher_name = publisher_name
    
        def __str__(self):
            return """
            Topic: {self.topic}
    
            {self.description}
    
            Age limit: {self.age_limit}
            produced by {self.publisher_name}
    
            """.format(self=self)
    
    class Channel(object):
        """
        mediator objects where messages are published by MediaPublishers 
        and where Customers subscribe for notification
        """
        def __init__(self, name):
            self.name = name
            self.programmes = []
            self.customers = []
    
        def schedule(self, programme):
            self.programmes.append(programme)
    
        def subscribe(self, customer):
            #print "{customer_name} has subscribed to channel {channel_name}".format(customer_name=customer.name,
            #                                                                       channel_name=self.name)
            self.customers.append(customer)
    
        def notify_consumers(self):
            """
            notify all interested subscribers provided they are allowed to watch the programme
            """
            for customer in self.customers:        # iterate  over subscribers
                for programme in self.programmes:  # iterate through received messages, that is programmes
                    topic = programme.topic
                    age_limit = programme.age_limit
                    if topic in customer.interests:  # topic-based filtering
                        if age_limit > customer.age: # content-based filtering
                            print "{customer_name} cannot watch {programme.description}".format(customer_name=customer.name, programme=programme)
                        else:
                            customer.watch(programme)
                        print "    on channel '{name}'\n".format(name=self.name)
    
    
    
    class MediaPublisher(object):
        """
        message publisher
        """
    
        def __init__(self, name):
            self.name = name
    
        def get_programme(self, topic ):
            """
            builder method for Programmes
            """
            descriptions = {Topics.CARTOON: ["Tom and Jerry", "The Flintstones"],
                           Topics.FOOTBALL: ["the Champions Leage final", "a boring football match", "the World Cup semifinal"],
                           Topics.ACTION:  ["The Terminator", "Rambo XVIII", "Robocop", "Die hard 8"],
                           Topics.FAMILY:  ["Santa Clause gone mad", "Fishing on the lake", "The return of Easter Bunny"],
                           Topics.ROMANCE: ["Antonio and Cleopatra", "Love till you drop dead", "Never-ending love story"],
                           Topics.SCIFI: ["Star Wars XXVII", "Star Trek", "Andromeda", "Babylon 9"],
                }
            description = choice(descriptions[topic])
    
            if topic in (Topics.CARTOON, Topics.FOOTBALL, Topics.FAMILY): # kids safe
                age_limit = 0
            else:
                if randint(1,3) == 3:
                    age_limit = 0
                else:
                    age_limit = 14
    
            return Programme(topic, description, age_limit, self.name )
    
        def provide(self, channel, topic):
            """
            MediaPublisher sends a programme to Channel in this topic
            """
            programme = self.get_programme(topic)
            channel.schedule(programme)
    
    
    class Customer(object):
        """
        message subscriber
        """
        def __init__(self, name, age):
            self.name = name
            self.age = age
            self.interests = []
    
        def add_interest(self, interest):
            self.interests.append(interest)
    
        def subscribe(self, channel):
            channel.subscribe(self)
    
        def watch(self, programme):
            print "{name} is going to watch a {programme.description} made by {programme.publisher_name}".format(name=self.name,
                                                                                                                 programme=programme)
    
        def __str__(self):
            return """
            Customer records:
                name : {self.name}
                age  : {self.age}
                interests: {self.interests}
            """.format(self=self)
    
    
    
    if __name__ == "__main__":
    
        # initialize system
    
        john = Customer("John Doe", 45)
        john.add_interest(Topics.SCIFI)
        john.add_interest(Topics.ACTION)
        john.add_interest(Topics.FOOTBALL)
    
        mary = Customer("Mary Popkins", 54)
        mary.add_interest(Topics.ROMANCE)
        mary.add_interest(Topics.FAMILY)
    
        pete = Customer("Pete Little", 9)
        pete.add_interest(Topics.CARTOON)
        pete.add_interest(Topics.FOOTBALL)
        pete.add_interest(Topics.ACTION)
        pete.add_interest(Topics.FAMILY)
    
        funcaster = Channel("The Funstatic Caster")
        kill_your_time = Channel("Kill All Your Time with US")
        public_services = Channel("Taxpayer paid")
        channels = [funcaster, kill_your_time, public_services]
    
        # subscriptions
        john.subscribe(funcaster)
        john.subscribe(kill_your_time)
        john.subscribe(public_services)
    
        mary.subscribe(funcaster)
        mary.subscribe(public_services)
    
        pete.subscribe(funcaster)
        pete.subscribe(kill_your_time)
    
    
        doozney_productions = MediaPublisher("Doozney Inc")
        lion_studio   = MediaPublisher("Lions and Lambs Studio")
    
        def cast_dice():
            return randint(1,6)
    
        # decide on broadcasting
        for topic in Topics.all_topics():
    
            if cast_dice() <= 3:
                doozney_productions.provide(public_services, topic)
            else:
                doozney_productions.provide(funcaster, topic)
                doozney_productions.provide(kill_your_time, topic)
    
            if cast_dice() >= 5:
                lion_studio.provide(public_services, topic)
                lion_studio.provide(kill_your_time, topic)
            else:
                lion_studio.provide(funcaster, topic)
    
        for channel in channels:
            channel.notify_consumers()
    

    public by cghersi @ PLAT.ONE  3635  2  6  0

    How to consume JMS frames directly incoming from devices in PLAT.ONE

    This class can be used and modified to manage the JMS frames incoming in real time from the PLAT.ONE JMS Broker. The edgeware component of PLAT.ONE, that manages a set of devices, retrieves the information from the devices and publishes those information onto some JMS topics. This class represents a client that subscribes to those topics and is not
    package one.plat.extensions;
    
    import java.util.List;
    
    import helloworldservice.HelloWorldServiceImpl;
    
    import com.abodata.plat1.frames.dataTypeCode;
    import com.abodata.plat1.frames.serviceTypeCode;
    import com.abodata.plat1.jms.IDirectAMQConsumer;
    import com.abodata.plat1.jms.INetworkSubscriber;
    import com.abodata.plat1.jms.Interest;
    import com.abodata.plat1.jms.InterestType;
    import com.abodata.plat1.jms.MsgFormat;
    import com.abodata.plat1.jms.SIPCInterface;
    import com.abodata.plat1.logger.Plat1Logger;
    import com.abodata.plat1.network.addressing.NodeIdentifier;
    import com.abodata.plat1.network.node.data.Measure;
    import com.abodata.plat1.network.node.data.ParsedMeasurePayload;
    import com.abodata.plat1.network.node.data.PositionPayload;
    import com.abodata.plat1.queues.frames.BaseHeader;
    import com.abodata.plat1.queues.frames.Frame;
    import com.abodata.plat1.queues.frames.NextHeader;
    import com.abodata.plat1.queues.frames.Payload;
    import com.abodata.plat1.queues.frames.WSNDataHeader;
    import com.abodata.plat1.queues.frames.WSNnodeHeader;
    import com.abodata.plat1.ws.velocity.IProxyNetwork;
    
    public class DirectConsumer implements IDirectAMQConsumer, INetworkSubscriber {
    
    	private static final Plat1Logger log = new Plat1Logger(DirectConsumer.class);
    	
    	private InterestType[] interests = new InterestType[] {	
    			//get data from the field / devices
    			new InterestType(serviceTypeCode.doryService, dataTypeCode.dataPosition, false, this),
    			new InterestType(serviceTypeCode.doryService, dataTypeCode.dataAbsPosition, false, this),
    			new InterestType(serviceTypeCode.doryService, dataTypeCode.parsedDataReport, false, this), 
    
    			//check new networks
    			new InterestType(serviceTypeCode.wsnLifeService, dataTypeCode.event),	
    		};
    	
    	public void startConnection() {
    		log.warn("Start connection towards broker");
    		try {
    			HelloWorldServiceImpl.getAMQFactory().startConnection(getClass(), 
    					new Interest[] { 
    						new Interest(BaseHeader.BROADCAST_NETWORKID, serviceTypeCode.wsnLifeService, dataTypeCode.event, 
    									"", MsgFormat.XML, null, false) });
    			
    			HelloWorldServiceImpl.getAMQFactory().subscribeToNets(this, HelloWorldServiceImpl.getAPI().DB_GetVisibleNetworks());
    
    			
    			log.warn("Connection successfully opened!");
    		} catch (InstantiationException e) {
    			log.error("Cannot subscribe to nets due to " + e, e);
    		} catch (Exception e) {
    			log.error("Cannot subscribe to nets due to " + e, e);
    		}
    	}
    	
    	public void stopConnection() {
    		getSIPC().ipcClosePipe();
    		HelloWorldServiceImpl.getAMQFactory().remove(getClass());
    	}
    
    	@Override
    	public void consume(Frame frame) {
    		//filter unwanted frames:
    		BaseHeader bh = frame.getBHeader();
    		switch(bh.getDataType()) {
    		case parsedDataReport:
    			NextHeader header = frame.getNextHeader();
    			if ((header != null) && (header instanceof WSNDataHeader)) {
    				Payload p = frame.getPayload();
    				if ((p != null) && (p instanceof ParsedMeasurePayload))
    					manageDataFrame(bh, (WSNDataHeader)header, (ParsedMeasurePayload)p);
    			}
    			break;
    			
    		case dataPosition:
    		case dataAbsPosition:
    			NextHeader headerPos = frame.getNextHeader();
    			if ((headerPos != null) && (headerPos instanceof WSNnodeHeader)) {
    				Payload p = frame.getPayload();
    				if ((p != null) && (p instanceof PositionPayload))
    					managePositionFrame(bh, (WSNnodeHeader)headerPos, (PositionPayload)p);
    			}
    			break;
    			
    		default: //nothing to do here...
    			break;
    		}
    	}
    	
    	private void manageDataFrame(BaseHeader bh, WSNDataHeader header, ParsedMeasurePayload p) {
    		NodeIdentifier nodeID = header.getNodeId(); //device that sent the new data
    		
    		//which data configuration has been received (e.g. High=6 - Low=0 => OpMode)
    		int objIDHigh = header.getObjectIdHigh();
    		int objIDLow = header.getObjectIdLow();
    			
    		//actual value(s) of the data, with timestamp and unit(s) of measure.
    		//There can be several data associated to a single configuration, but usually there's just one information (m.getRank() = 1)
    		Measure m = p.getMeasure();	
    		
    		// do some stuff...
    	}
    	
    	private void managePositionFrame(BaseHeader bh, WSNnodeHeader header, PositionPayload p) {
    		NodeIdentifier nodeID = header.getNodeId(); //device that sent the new position
    		float[] coords = p.getCoords(); //new coordinates
    		
    		//whether those coordinates are absolute (latitude, longitude, quote), or relative (with respect to a known origin)
    		boolean isAbsCoords = bh.getDataType() == dataTypeCode.dataAbsPosition; 
    		
    		// do some stuff...
    	}
    
    	@Override
    	public InterestType[] getInterests() {
    		return interests;
    	}
    
    	@Override
    	public SIPCInterface getSIPC() {
    		return HelloWorldServiceImpl.getSIPC();
    	}
    	
    	@Override
    	public boolean isAbleToConsumeFrames() { return true; }
    	
    	@Override
    	public void consume(String arg0) {} //not used
    	@Override
    	public void consume(byte[] arg0) {} //not used
    	@Override
    	public boolean isAbleToConsumeBinaryMsg() {	return false; }
    	@Override
    	public boolean isAbleToConsumeTextMessages() { return false; }
    }            

    public by cghersi @ MailUp API DEV  1368  6  5  0

    How to Add a recipient to a list 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 AddRecipientToList(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 = "test@mailup.com",
            Name = "New Recipient" + DateTime.Now.ToFileTimeUtc(),
            Fields = new List<ConsoleRecipientDynamicFieldItem>()
            {
                new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name" + DateTime.Now.ToFileTimeUtc() },
                new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName" + 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);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        if (result > 0)
            Console.WriteLine("Recipient Added!");
        else
            Console.WriteLine("An error occurred while adding the recipient.");
    }
    

    public by cghersi @ MailUp API DEV  1557  3  6  0

    How to Unsubscribe a recipient from a list 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 UnsubscribeRecipient(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;
        int idRecipient = 1;
    
        // 3) Invoke the web method:
        try
        {
            client.UnsubscribeRecipient(idList, idRecipient);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        Console.WriteLine("Recipient unsubscribed.");
    }
    

    public by cghersi @ MailUp API DEV  1365  1  5  0

    How to Retrieve the status of a recipient given the ID 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 GetSubscriptionStatusByID(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;
        int idRecipient = 1;
    
        // 3) Invoke the web method:
        SubscriptionStatus result = SubscriptionStatus.Unknown;
        try
        {
            result = client.GetSubscriptionStatus(idList, idRecipient);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        Console.WriteLine("Recipient status: " + result);
    }
    

    public by cghersi @ MailUp API DEV  1061  4  6  0

    How to Retrieve the status of a recipient given the email 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 GetSubscriptionStatusByEmail(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;
        string emailRecipient = "test@mailup.com";
    
        // 3) Invoke the web method:
        SubscriptionStatus result = SubscriptionStatus.Unknown;
        try
        {
            result = client.GetSubscriptionStatus(idList, emailRecipient);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        Console.WriteLine("Recipient status: " + result);
    }
    
    • Public Snippets
    • Channels Snippets