Exemplo n.º 1
0
        public static void Main()
        {
            Mailgun.Init("key-afy6amxoo2fnj$u@mc");

            try
            {
                string sender = "*****@*****.**";
                string recipients = "You <*****@*****.**>, [email protected]";
                string rawMime =
@"X-Priority: 1 (Highest)
X-Mailgun-Tag: sample_raw
Content-Type: text/plain;charset=UTF-8
From: [email protected]
To: [email protected]
Subject: Hello raw API!

This message is sent by Mailgun C# API";

                // Send a simpe text message
                MailgunMessage.SendText(sender, recipients,
                    "Hello text API!", "Hi!\nI am sending the message using Mailgun C# API");
   
                // Send a simpe text message and tag it
                var options = new MailgunMessage.Options();
                options.SetHeader(MailgunMessage.MAILGUN_TAG, "sample_text");
                MailgunMessage.SendText(sender, recipients,
                                        "Hello text API + tag!", "Hi!\nI am sending the message using Mailgun C# API and setting the tag",
                                        options);

                // Send a MIME message
                MailgunMessage.SendRaw(sender, recipients, Encoding.UTF8.GetBytes(rawMime));
				
                // .NET Framework also has System.Net.Mail.MailMessage class which simplifies
                // MIME constriction. MailMessage can be sent by System.Net.Mail.SmtpClient class.
                // Login into Mailgun Control Panel and look for your SMTP server address, user and password.

                Console.WriteLine("Messages sent");
            }
            catch (MailgunException ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send plain-text message
        /// </summary>
        /// <param name="sender">sender specification</param>
        /// <param name="recipients">comma- or semicolon-separated list of recipients specifications</param>
        /// <param name="subject">message subject</param>
        /// <param name="text">message text</param>
        /// <param name="servername">sending server (can be empty, use 'best' server)</param>
        /// <param name="options">sending options (e.g. add headers to message)</param>
        public static void SendText(string sender, string recipients, string subject, string text, string servername, MailgunMessage.Options options)
        {
            NameValueCollection req = new NameValueCollection();

            req.Add("sender", sender);
            req.Add("recipients", recipients);
            req.Add("subject", subject);
            req.Add("body", text);
            if (options != null)
            {
                req.Add("options", options.toJSON());
            }

            byte[]         data = getWWWFormData(req);
            HttpWebRequest wr   = Mailgun.OpenRequest(messagesUrl("txt", servername), "POST");

            wr.ContentType   = "application/x-www-form-urlencoded";
            wr.ContentLength = data.Length;
            using (Stream rs = Mailgun.GetRequestStream(wr))
                rs.Write(data, 0, data.Length);

            using (Mailgun.SendRequest(wr)) {
            }
        }
Exemplo n.º 3
0
 public static void SendText(string sender, string recipients, string subject, string text, MailgunMessage.Options options)
 {
     SendText(sender, recipients, subject, text, "", options);
 }