Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var emailService = new AlphaMailEmailService("YOUR-ACCOUNT-API-TOKEN-HERE");

            var message = new
            {
                Message = "Hello world like a boss!",
                SomeOtherMessage = "And to the rest of the world! Chíkmàa! مرحبا! नमस्ते! Dumelang!"
            };

            var payload = new EmailMessagePayload()
                .SetProjectId(12345) // The id of the project your want to send with
                .SetSender(new EmailContact("Sender Company Name", "*****@*****.**"))
                .SetReceiver(new EmailContact("Joe E. Receiver", "*****@*****.**"))
                .SetBodyObject(message);

            try
            {
                var response = emailService.Queue(payload);
                Console.WriteLine("Mail successfully sent! ID = {0}", response.Result);
            }
            catch (AlphaMailServiceException exception)
            {
                Console.WriteLine("Error! {0} ({1})", exception.Message, exception.GetErrorCode());
            }

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Step #1: Let's start by entering the web service URL and the API-token you've been provided
            // If you haven't gotten your API-token yet. Log into AlphaMail or contact support at '*****@*****.**'.
            IEmailService emailService = new AlphaMailEmailService()
                .SetServiceUrl("http://api.amail.io/v2/")
                .SetApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");

            // Step #2: Let's fill in the gaps for the variables (stuff) we've used in our template
            var message = new HelloWorldMessage()
            {
                Message = "Hello world like a boss!",
                SomeOtherMessage = "And to the rest of the world! Chíkmàa! مرحبا! नमस्ते! Dumelang!"
            };

            // Step #3: Let's set up everything that is specific for delivering this email
            var payload = new EmailMessagePayload()
                .SetProjectId(12345) // The id of the project your want to send with
                .SetSender(new EmailContact("Sender Company Name", "*****@*****.**"))
                .SetReceiver(new EmailContact("Joe E. Receiver", "*****@*****.**"))
                .SetBodyObject(message);

            try
            {
                // Step #4: Haven't we waited long enough. Let's send this!
                var response = emailService.Queue(payload);

                // Step #5: Pop the champagné! We got here which mean that the request was sent successfully and the email is on it's way!
                Console.WriteLine("Successfully queued message with id '{0}' (you can use this ID to get more details about the delivery)", response.Result);
            }
            // Oh heck. Something went wrong. But don't stop here.
            // If you haven't solved it yourself. Just contact our brilliant support and they will help you.
            catch (AlphaMailValidationException exception)
            {
                // Example: Handle request specific error code here
                if (exception.Response.ErrorCode == 3)
                {
                    // Example: Print a nice message to the user.
                }
                else
                {
                    // Something in the input was wrong. Probably good to double double-check!
                    Console.WriteLine("Validation error: {0} ({1})", exception.Response.Message, exception.Response.ErrorCode);
                }
            }
            catch (AlphaMailAuthorizationException exception)
            {
                // Ooops! You've probably just entered the wrong API-token.
                Console.WriteLine("Authentication error: {0} ({1})", exception.Response.Message, exception.Response.ErrorCode);
            }
            catch (AlphaMailInternalException exception)
            {
                // Not that it is going to happen.. Right :-)
                Console.WriteLine("Internal error: {0} ({1})", exception.Response.Message, exception.Response.ErrorCode);
            }
            catch (AlphaMailServiceException exception)
            {
                // Most likely your internet connection that is down. We are covered for most things except "multi-data-center-angry-server-bashing-monkeys" (remember who coined it) or.. nuclear bombs.
                // If one blew. Well.. It's just likely that our servers are down.
                Console.WriteLine("An error (probably related to connection) occurred: {0}", exception);
            }

            // Writing to console like a boss
            Console.WriteLine("\n\tIn doubt or experiencing problems?\n" +
                "\tPlease email our support at '*****@*****.**'");

            // This was exhausting. Let's grab a beer.
            Console.WriteLine("\nPress any key to terminate..");
            Console.ReadLine();
        }