예제 #1
0
파일: Mailer.cs 프로젝트: truekasun/SendIt
 public string SendEmail(Email email)
 {
     WebClient client = new WebClient();
     NameValueCollection values = new NameValueCollection();
     values.Add("username", Username);
     values.Add("api_key", ApiKey);
     values.Add("from", email.From);
     values.Add("from_name", email.Name);
     values.Add("subject", email.Subject);
     if (email.BodyHtml != null)
         values.Add("body_html", email.BodyHtml);
     if (email.BodyText != null)
         values.Add("body_text", email.BodyText);
     values.Add("to", email.To);
     byte[] response = client.UploadValues("https://api.elasticemail.com/mailer/send", values);
     return Encoding.UTF8.GetString(response);
 }
예제 #2
0
        public HttpResponseMessage Send(Email message)
        {
            var retObj = new SendResult();

            if (message.To != null && message.From != null) {
                var mailer = new Mailer();
                retObj.Message = mailer.SendEmail(message);

                if (retObj.Message.Contains("Error")) {
                    retObj.Status=false;
                    return Request.CreateResponse(HttpStatusCode.BadRequest, retObj);
                }
                retObj.Status = true;
                return Request.CreateResponse(HttpStatusCode.OK, retObj);
            }
            retObj.Status = false;
            retObj.Message = "Invalid Content";
            return Request.CreateResponse(HttpStatusCode.NotFound, retObj);
        }