Exemplo n.º 1
0
        public static List<EmailResult> SendMail(List<string> toMails, string subject, string htmlBody, bool async = false)
        {
            try
            {
                var api = new MandrillApi(_mandrillApiKey);

                var email = new EmailMessage()
                {
                    from_email = _senderEmail,
                    subject = subject,
                    html = htmlBody
                };
                var to = toMails.Select(mailTo => new EmailAddress(mailTo)).ToList();

                email.to = to;
                if (async)
                {
                    var result = api.SendMessageAsync(email);
                    return result.Result;
                }
                return api.SendMessage(email);
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Exemplo n.º 2
0
        protected async void Button1_Click(object sender, EventArgs e)
        {




                MandrillApi api = new MandrillApi("Mandrill Api Key", true);

                IEnumerable<EmailAddress> addresses = new[]
            {
                new EmailAddress("*****@*****.**", "Name Of the Contact"),
                
            };




                var message = new EmailMessage();

                message.FromEmail = "*****@*****.**";
                message.FromName = "Your name";
            message.Html = "emailbody";
                message.Text = "emailbodytext";
            message.Subject = "subject";
                message.To = addresses;
              

                SendMessageRequest req = new SendMessageRequest(message);

                var returnvalue = await api.SendMessage(req);
             
            }
Exemplo n.º 3
0
        public string SendMail(string from, string passsword, string to, string bcc, string cc, string subject, string body, string MandrillUserName = "", string MandrillPassword = "")
        {
            string sendMailByMandrill = string.Empty;

            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email = from;
                message.from_name  = from;
                message.html       = body;
                message.subject    = subject;
                message.to         = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(to)
                };
                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(MandrillPassword, false);
                var results = mandrillApi.SendMessage(message);

                foreach (var result in results)
                {
                    if (result.Status != Mandrill.EmailResultStatus.Sent || result.Status == Mandrill.EmailResultStatus.Queued)
                    {
                        sendMailByMandrill = "Success";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(sendMailByMandrill);
        }
Exemplo n.º 4
0
        public override void Execute()
        {
            var apiKey = EnvironmentVariableHelper.GetEnvironmentVariable(mandrillAPIKey);
              var fromEmail = EnvironmentVariableHelper.GetEnvironmentVariable(fromEmailKey);

              var api = new MandrillApi (apiKey);

              Console.WriteLine("Sending {0} emails.", In.DueReminders.Length);
              foreach (var reminder in In.DueReminders) {
            var results = api.SendMessage(
              new EmailMessage {
            to = new List<EmailAddress> { new EmailAddress { email = reminder.Contact } },
            from_email = fromEmail,
            subject = "Reminder!",
            text = reminder.Message
            });

            // This assumes that emails are sent one at time to each address, therefore just look
            // at the first result.
            EmailResult result = results[0];
            if (result.Status == EmailResultStatus.Sent) {
              Out.Sent++;
            } else {
              Out.Errors++;
              Console.WriteLine(
            "Email {0} failed with a status of {1} and reason of {2}.",
            result.Email,
            result.Status,
            result.RejectReason
              );
            }
              }
        }
        public void SendEmail()
        {
            //create a new message object
            var message = new MandrillApi(Apikey, true);

            //send the mail
            try
            {
                var emailMessage = new EmailMessage()
                {
                    to = To,
                    subject = Subject,
                    raw_message = Message,
                    from_email = From.email,
                    from_name = From.name
                };

                //message.SendRawMessage(emailMessage);

                message.SendMessage(To, Subject, Message, From, new DateTime());
            }
            catch (System.Exception ex)
            {
                throw;
                // log the error
            }
        }
        public string SendMail(string from, string passsword, string to, string bcc, string cc, string subject, string body, string MandrillUserName = "", string MandrillPassword = "")
        {
            string sendMailByMandrill = string.Empty;
            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email = from;
                message.from_name = from;
                message.html = body;
                message.subject = subject;
                message.to = new List<Mandrill.EmailAddress>()
                {
                  new Mandrill.EmailAddress(to)
                };
                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(MandrillPassword, false);
                var results = mandrillApi.SendMessage(message);

                foreach (var result in results)
                {
                    if (result.Status != Mandrill.EmailResultStatus.Sent || result.Status == Mandrill.EmailResultStatus.Queued)
                    {
                        sendMailByMandrill = "Success";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return sendMailByMandrill;
        }
Exemplo n.º 7
0
        public static async void EnviarMailRegistro(string nombreFranquicia, string from, string para, string nombrePara, string confirmKey,
            string nombre, string password)
        {
            MandrillApi api = new MandrillApi("aEBsx-ctFG9KeItcRm5aCQ");
            UserInfo info = await api.UserInfo();
            Console.WriteLine(info.Username);

            var email = new Mandrill.Models.EmailMessage();

            var correos = new List<EmailAddress>();
            correos.Add(new EmailAddress(para, nombrePara));

            email.To = correos;

            email.Subject = String.Format("Confirmación de registro a {0}", nombreFranquicia);

            email.FromEmail = from;
            email.FromName = nombreFranquicia;


            email.TrackOpens = true;
            email.Html =
                $"Hola {nombrePara}, url: {"http://localhost:49608/Usuario/ConfirmacionCorreo?confirmKey=" + confirmKey} Adicionalmente, esta es tu password para cambiar la contraseña: { password }";

            await api.SendMessage(new SendMessageRequest(email));
        }
Exemplo n.º 8
0
        public string ReplyForCareerMail(string from, string body, string subject, string to, string password)
        {
            string sendMailByMandrill = string.Empty;

            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email = from;
                message.from_name  = "Socioboard Support";
                message.html       = body;
                message.subject    = subject;
                message.to         = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(to)
                };
                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(password, false);
                var    results = mandrillApi.SendMessage(message);
                string status  = string.Empty;
                foreach (var result in results)
                {
                }
                sendMailByMandrill = "Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                sendMailByMandrill = ex.Message;
            }
            return(sendMailByMandrill);
        }
Exemplo n.º 9
0
        public string SendInvitationMailByMandrill(string SenderEmail, string SenderName, string FriendsEmail, string password, string body)
        {
            string sendMailByMandrill = string.Empty;

            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email = SenderEmail;
                message.from_name  = SenderName;
                message.html       = body;
                message.subject    = "Your friend " + SenderName + "has invited you to join socioboard";
                message.to         = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(FriendsEmail)
                };
                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(password, false);
                var results = mandrillApi.SendMessage(message);
                foreach (var result in results)
                {
                    if (result.Status == Mandrill.EmailResultStatus.Sent || result.Status == Mandrill.EmailResultStatus.Queued)
                    {
                        sendMailByMandrill = "success";
                    }
                    else
                    {
                        sendMailByMandrill = "failed";
                    }
                }
            }
            catch (Exception ex)
            {
                sendMailByMandrill = "failed";
            }
            return(sendMailByMandrill);
        }
Exemplo n.º 10
0
        //static string MandrillBaseUrl = ConfigurationManager.AppSettings["smtp.mandrillapp.com"];
        //static Guid MandrillKey = new Guid(ConfigurationManager.AppSettings["xBhdpEwsVOC689CTDqzlkw"]);

        public static void SendSingleMail(List <M.EmailAddress> argToAddress, string argSubject, string argContent, List <M.attachment> argAttachment)
        {
            try
            {
                //string activationLink = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Register/Activation.aspx?id=" + "";

                Cursor.Current = Cursors.WaitCursor;

                DataTable dt = new DataTable();
                dt = CommFun.GetMandrillSetting(2);
                if (dt == null)
                {
                    return;
                }
                if (dt.Rows.Count == 0)
                {
                    return;
                }

                string sFromName     = CommFun.IsNullCheck(dt.Rows[0]["FromName"], CommFun.datatypes.vartypestring).ToString();
                string sUserId       = CommFun.IsNullCheck(dt.Rows[0]["UserId"], CommFun.datatypes.vartypestring).ToString();
                string sKeyId        = CommFun.IsNullCheck(dt.Rows[0]["KeyId"], CommFun.datatypes.vartypestring).ToString();
                string sTemplateName = CommFun.IsNullCheck(dt.Rows[0]["TemplateId"], CommFun.datatypes.vartypestring).ToString();

                M.MandrillApi api = new M.MandrillApi(sKeyId, true);

                M.EmailMessage emailmsg = new M.EmailMessage();
                emailmsg.from_name   = sFromName;
                emailmsg.from_email  = sUserId;
                emailmsg.to          = argToAddress;
                emailmsg.attachments = argAttachment;
                emailmsg.merge       = true;
                emailmsg.AddGlobalVariable("SUBJECT", argSubject);
                emailmsg.AddGlobalVariable("BODY", argContent);

                emailmsg.AddGlobalVariable("FlatNo", "5-102");
                emailmsg.AddGlobalVariable("PaidAmount", "0");
                emailmsg.AddGlobalVariable("Balance", "6,70,070.00");
                emailmsg.AddGlobalVariable("Project", "Sky Dugar");
                emailmsg.AddGlobalVariable("Company", "Dugar");

                List <M.TemplateContent> tempContent = new List <M.TemplateContent>();
                tempContent.Add(new M.TemplateContent()
                {
                    name = sTemplateName
                });

                List <M.EmailResult> errorMsg = api.SendMessage(emailmsg, sTemplateName, tempContent);

                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 11
0
        //vikash
        public string SendCareerMailByMandrill(string Host, int port, string from, string passsword, string to, string bcc, string cc, string subject, string body, string sendgridUserName, string sendgridPassword, string file, string filename, string filetype)
        {
            string sendMailByMandrill = string.Empty;

            try
            {
                var fileBytes = File.ReadAllBytes(file);
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email  = from;
                message.from_name   = "Socioboard Support";
                message.html        = body;
                message.subject     = subject;
                message.attachments = new[]
                {
                    new attachment
                    {
                        content = Convert.ToBase64String(fileBytes),
                        name    = filename,
                        type    = filetype
                    }
                };
                message.to = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(to)
                };
                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(sendgridPassword, false);
                var    results = mandrillApi.SendMessage(message);
                string status  = string.Empty;
                foreach (var result in results)
                {
                    if (result.Status != Mandrill.EmailResultStatus.Sent)
                    {
                        logger.Error(result.Email + " " + result.RejectReason);
                    }
                }

                sendMailByMandrill = "Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                sendMailByMandrill = ex.Message;
            }

            return(sendMailByMandrill);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Send an email
        /// </summary>
        /// <param name="request">Contains detailed email info and optionally provider info (such as ApiKeys)</param>
        /// <param name="messageId">The message id returned by the service provider</param>
        /// <param name="detailMessage">The message returned by the service provider, e.g. "failed to send message", "Sent", "Message Queued for delivery"</param>
        /// <returns>True if email was sent successfully</returns>
        public override bool SendMail(SendMailRequest request, out string messageId, out string detailMessage)
        {
            // Create request
            string apiKey = GetApiKey(request);
            MandrillApi api = new MandrillApi(apiKey);

            // Email details
            EmailMessage msg = new EmailMessage();
            msg.FromEmail = request.From;
            msg.To = request.To.Select(e=>new EmailAddress(e));
            msg.Text = request.Text;

            // Send email
            SendMessageRequest smReq = new SendMessageRequest(msg);
            Task<List<EmailResult>> task = api.SendMessage(smReq);
            task.Wait();

            // process response
            messageId = "";
            detailMessage = "";

            EmailResult er = null;
            if (task.Result != null && task.Result.Count >0)
            {
                er = task.Result[0];
            }

            if (er == null)
            {
                detailMessage = "Invalid return result from provider.";
                return false;
            }

            messageId = er.Id;
            detailMessage = er.Status.ToString();

            if (er.Status == EmailResultStatus.Queued
                || er.Status == EmailResultStatus.Scheduled
                || er.Status == EmailResultStatus.Sent)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 13
0
        public string SendMailByMandrill(string Host, int port, string from, string name, string passsword, string to, string bcc, string cc, string subject, string body, string sendgridUserName, string sendgridPassword)
        {
            string sendMailByMandrill = string.Empty;

            //GetStatusFromSendMailByMandrill(Host, port, from, passsword, to, bcc, cc, subject, body, sendgridUserName, sendgridPassword);

            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                //message.from_email = from;
                //message.from_name = from;//"AlexPieter";
                message.from_email = from;
                message.from_name  = name;
                message.html       = body;
                message.subject    = subject;
                message.to         = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(to)
                };

                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(sendgridPassword, false);
                var    results = mandrillApi.SendMessage(message);
                string status  = string.Empty;
                foreach (var result in results)
                {
                    if (result.Status != Mandrill.EmailResultStatus.Sent)
                    {
                        logger.Error(result.Email + " " + result.RejectReason);
                    }
                    //status = Mandrill.EmailResultStatus.Sent.ToString();
                    //  LogManager.Current.LogError(result.Email, "", "", "", null, string.Format("Email failed to send: {0}", result.RejectReason));
                }

                sendMailByMandrill = "Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                sendMailByMandrill = ex.Message;
            }

            return(sendMailByMandrill);
        }
Exemplo n.º 14
0
 public void SendAcceptanceNotificationToGroup(Member member)
 {
     var api = new MandrillApi(_configuration.MadrillApiKey);
     var result = api.SendMessage(
         new EmailMessage()
         {
             to =
                 new List<EmailAddress>()
                 {
                     new EmailAddress {email = _configuration.MadrillOriginTarget}
                 },
             subject = member.FullName
         },
         "devlink-accept-invitation",
         new List<TemplateContent>()
         {
             new TemplateContent() {name = "candidate", content = member.FullName},
         });
 }
Exemplo n.º 15
0
        public string SendMailWithAttachment(string from, string passsword, string to, string bcc, string cc, string subject, string body, string file, string filename, string filetype, string MandrillUserName = "", string MandrillPassword = "")
        {
            string sendMailByMandrill = string.Empty;

            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email = from;
                message.from_name  = from;
                message.html       = body;
                message.subject    = subject;
                var fileBytes = File.ReadAllBytes(file);
                message.attachments = new[]
                {
                    new attachment
                    {
                        content = Convert.ToBase64String(fileBytes),
                        name    = filename,
                        type    = filetype
                    }
                };
                message.to = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(to)
                };
                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(MandrillPassword, false);
                var results = mandrillApi.SendMessage(message);

                foreach (var result in results)
                {
                    if (result.Status != Mandrill.EmailResultStatus.Sent || result.Status == Mandrill.EmailResultStatus.Queued)
                    {
                        sendMailByMandrill = "Success";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(sendMailByMandrill);
        }
Exemplo n.º 16
0
        public string SendMailWithAttachment(string from, string passsword, string to, string bcc, string cc, string subject, string body, string file, string filename, string filetype, string MandrillUserName = "", string MandrillPassword = "")
        {
            string sendMailByMandrill = string.Empty;
            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email = from;
                message.from_name = from;
                message.html = body;
                message.subject = subject;
                var fileBytes = File.ReadAllBytes(file);
                message.attachments = new[]
                              {
                                  new attachment
                                  {
                                      content = Convert.ToBase64String(fileBytes),
                                      name = filename,
                                      type = filetype
                                  }
                              };
                message.to = new List<Mandrill.EmailAddress>()
                {
                  new Mandrill.EmailAddress(to)
                };
                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(MandrillPassword, false);
                var results = mandrillApi.SendMessage(message);

                foreach (var result in results)
                {
                    if (result.Status != Mandrill.EmailResultStatus.Sent || result.Status == Mandrill.EmailResultStatus.Queued)
                    {
                        sendMailByMandrill = "Success";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return sendMailByMandrill;
        }
Exemplo n.º 17
0
        public string SendAddNewsLatterMail(string Host, int port, string from, string passsword, string to, string subject, string body)
        {
            string sendMailByMandrill = string.Empty;

            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email = from;
                message.from_name  = from;
                message.html       = body;
                message.subject    = subject;
                message.to         = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(to)
                };

                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(passsword, false);
                var results = mandrillApi.SendMessage(message);

                foreach (var result in results)
                {
                    if (result.Status != Mandrill.EmailResultStatus.Sent)
                    {
                        // logger.Error(result.Email + " " + result.RejectReason);
                    }
                    //  LogManager.Current.LogError(result.Email, "", "", "", null, string.Format("Email failed to send: {0}", result.RejectReason));
                }

                sendMailByMandrill = "Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //logger.Error(ex.Message);
            }

            return(sendMailByMandrill);
        }
Exemplo n.º 18
0
 public void SendInvitationToGroup(Invitation invitation, string vouched)
 {
     var api = new MandrillApi(_configuration.MadrillApiKey);
     var result = api.SendMessage(
         new EmailMessage()
         {
             to =
                 new List<EmailAddress>()
                 {
                     new EmailAddress {email = _configuration.MadrillOriginTarget}
                 },
             subject = invitation.FullName
         },
         "devlink-submit-invitation",
         new List<TemplateContent>()
         {
             new TemplateContent() {name = "candidate", content = invitation.FullName},
             new TemplateContent() {name = "linkedin", content = invitation.LinkedIn},
             new TemplateContent() {name = "github", content = invitation.GitHub},
             new TemplateContent() {name = "vouchedby", content = vouched},
             new TemplateContent() {name = "testimonal", content = invitation.Testimonial}
         });
 }
Exemplo n.º 19
0
        /// <summary>
        /// SendMailByMandrill
        /// this function is used for sending mail vai Mandrill</summary></summary>
        /// the main parameter is
        /// <add key="host" value="smtp.mandrillapp.com" />
        /// <param name="port"></param>
        /// <add key="port" value="25" />
        /// <param name="from"></param>
        /// <add key="username" value="socioboard"/>
        /// <param name="passsword"></param>
        /// <add key="fromemail" value="*****@*****.**"/>
        /// <param name="to"></param>
        /// <add key="password" value="xyz" />
        /// <param name="bcc"></param>
        /// add key="tomail" value="*****@*****.**" />
        /// its return : EmailResultStatus i.e Sent, Rejected etc.
        /// <param name="cc"></param>
        /// <param name="Host"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="sendgridUserName"></param>
        /// <param name="sendgridPassword"></param>
        /// <returns></returns>
        public string GetStatusFromSendMailByMandrill(string Host, int port, string from, string passsword, string to, string bcc, string cc, string subject, string body, string sendgridUserName, string sendgridPassword)
        {
            string sendMailByMandrill = string.Empty;
            try
            {

                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                //message.from_email = from;
                //message.from_name = from;//"AlexPieter";
                message.from_email = from;
                message.from_name = "Socioboard Support";
                message.html = body;
                message.subject = subject;
                message.to = new List<Mandrill.EmailAddress>()
                {
                  new Mandrill.EmailAddress(to)
                };

                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(sendgridPassword, false);

                //List<RejectInfo> ri=mandrillApi.ListRejects();

                var results = mandrillApi.SendMessage(message);
                string status = string.Empty;
                foreach (var result in results)
                {
                    try
                    {
                        if (result.Status != Mandrill.EmailResultStatus.Sent)
                        {
                            logger.Error(result.Email + " " + result.RejectReason);

                        }

                        if (Mandrill.EmailResultStatus.Sent == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Sent.ToString();
                        }
                        else if (Mandrill.EmailResultStatus.Invalid == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Invalid.ToString();
                        }
                        else if (Mandrill.EmailResultStatus.Queued == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Queued.ToString();
                        }
                        else if (Mandrill.EmailResultStatus.Rejected == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Rejected.ToString();
                        }
                        else if (Mandrill.EmailResultStatus.Scheduled == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Scheduled.ToString();
                        }
                        else
                        {
                            status = result.RejectReason;
                        }
                        //status = Mandrill.EmailResultStatus;
                        //  LogManager.Current.LogError(result.Email, "", "", "", null, string.Format("Email failed to send: {0}", result.RejectReason));

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        logger.Error(ex.Message);
                        sendMailByMandrill = ex.Message;
                    }
                }

                sendMailByMandrill = status;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                sendMailByMandrill = ex.Message;
            }

            return sendMailByMandrill;
        }
Exemplo n.º 20
0
        public bool SendNotification(string toEmail, string bccEmail)
        {
            bool isDebugOnly = false;
            try
            {
                MailMessage mail = new MailMessage();

                if (ConfigurationManager.AppSettings["DebugEmailAddress"] != "")
                {
                    toEmail = ConfigurationManager.AppSettings["DebugEmailAddress"].ToString();
                    isDebugOnly = true;
                }
                if (!SendViaAPI)
                {
                    //send via standard SMTP
                    //split list of addresses
                    string[] addresses = toEmail.Split(';');

                    foreach (string emailAddress in addresses)
                    {
                        mail.To.Add(emailAddress);
                    }

                    if (!String.IsNullOrEmpty(bccEmail) && !isDebugOnly)
                    {
                        addresses = bccEmail.Split(';');
                        foreach (string emailAddress in addresses)
                        {
                            mail.Bcc.Add(emailAddress);
                        }
                    }

                    mail.From = new MailAddress(ConfigurationManager.AppSettings["DefaultSenderEmailAddress"], "openchargemap.org - automated notification");
                    mail.Subject = this.Subject;

                    AlternateView htmlView = AlternateView.CreateAlternateViewFromString(MessageBody, null, "text/html");

                    mail.AlternateViews.Add(htmlView);
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = System.Configuration.ConfigurationManager.AppSettings["SMTPHost"];
                    if (!String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["SMTPUser"]))
                    {
                        NetworkCredential basicCredential = new NetworkCredential(ConfigurationManager.AppSettings["SMTPUser"], ConfigurationManager.AppSettings["SMTPPwd"]);
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials = basicCredential;

                        //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                        //smtp.Port = 587;
                    }
                    //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                    try
                    {
                        smtp.Send(mail);
                    }
                    catch (Exception)
                    {
                        ; ;// failed to send
                        return false;
                    }

                    return true;
                }
                else
                {
                    //send via bulk mailing api
                    var apiKey = System.Configuration.ConfigurationManager.AppSettings["MandrillAPIKey"];
                    if (!String.IsNullOrEmpty(apiKey))
                    {
                        MandrillApi api = new MandrillApi(apiKey);
                        var message = new EmailMessage();

                        string[] addresses = toEmail.Split(';');
                        var emailToList = new List<EmailAddress>();
                        foreach (string emailAddress in addresses)
                        {
                            emailToList.Add(new EmailAddress(emailAddress));
                        }
                        message.To = emailToList;

                        if (!String.IsNullOrEmpty(bccEmail) && !isDebugOnly)
                        {
                            addresses = bccEmail.Split(';');
                            var bccToList = new List<EmailAddress>();
                            foreach (string emailAddress in addresses)
                            {
                                bccToList.Add(new EmailAddress(emailAddress));
                            }
                        }

                        message.FromEmail = ConfigurationManager.AppSettings["DefaultSenderEmailAddress"];
                        message.FromName = "Open Charge Map - Automated Notification";
                        message.Subject = this.Subject;

                        message.AutoText = true;
                        message.Html = this.MessageBody;

                        var messageRequest = new Mandrill.Requests.Messages.SendMessageRequest(message);

                        var messageTask = Task.Run(async () =>
                        {
                            return await api.SendMessage(messageRequest);
                        });

                        messageTask.Wait();
                        var result = messageTask.Result;
                        if (result != null && result.Any())
                        {
                            //optional notification result logging
                            LogEvent(Newtonsoft.Json.JsonConvert.SerializeObject(new { eventDate = DateTime.UtcNow, result = result }));

                            var r = result.First();
                            if (r.Status == EmailResultStatus.Invalid || r.Status == EmailResultStatus.Rejected)
                            {
                                return false;
                            }
                        }
                        else
                        {
                            LogEvent(Newtonsoft.Json.JsonConvert.SerializeObject(new { eventDate = DateTime.UtcNow, result = result }));
                        }

                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                LogEvent(Newtonsoft.Json.JsonConvert.SerializeObject(new { eventDate = DateTime.UtcNow, result = ex }));
            }

            return false;
        }
Exemplo n.º 21
0
        public string SendDemoMailByMandrill(string Host, int port, string from, string passsword, string to, string bcc, string cc, string subject, string body, string sendgridUserName, string sendgridPassword)
        {
            string sendMailByMandrill = string.Empty;

            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                message.from_email = from;
                message.from_name  = sendgridUserName;
                message.html       = body;
                message.subject    = subject;
                message.to         = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(to)
                };
                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(sendgridPassword, false);
                var    results      = mandrillApi.SendMessage(message);
                string status       = string.Empty;
                string replysubject = string.Empty;
                string replybody    = string.Empty;
                foreach (var result in results)
                {
                    if (result.Status == Mandrill.EmailResultStatus.Sent || result.Status == Mandrill.EmailResultStatus.Queued)
                    {
                        replysubject = "Request Rcieved";
                        replybody    = "Hello there,</br>We have received your request for a demo. </br>Our Support team will connect to you in time.</br>Warm regards,<p>Best regards,<br/><br />" +
                                       "Support Team<br/>Socioboard Technologies Pvt. Ltd.<br /><br /><a href=\"http://www.socioboard.com\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/logo-txt2_zpsc7861ad5.png\" alt=\"\"></a></p>" +
                                       "<p style=\"font-family:Calibri(Body); font-size:12px;.\"><b>Mumbai Office:</b> Unit 206, Shri Krishna Building,Lokhandwala, Andheri West,Mumbai 400053India </br>" +
                                       "<b>Phone:</b> +91-90090-23807, <b>Skype:</b> socioboard.support </br>Socioboard Enterprise and SaaS Versions: <a href=\"http://www.socioboard.com\">http://www.socioboard.com<br /></a> Socioboard Community Version: <a href=\"http://www.socioboard.org\">http://www.socioboard.org</a><br>" +
                                       "</p><table><tr><td><a href=\"https://www.facebook.com/SocioBoard\" target=\"_blank\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/facebook-48_zps62d89d59.png\" alt=”Facebook” width=”35? height=”35? border=0></a></td>" +
                                       "<td><a href=\"https://plus.google.com/s/socioboard\" target=\"_blank\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/googleplus-30_zps62d89d59.png\" alt=\"G+\"width=”35? height=”35? border=0></a></td>" +
                                       "<td><a href=\"http://www.linkedin.com/company/socioboard\" target=\"_blank\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/linkedin-48_zpsceb0f4e2.png\" alt=”LinkedIn” width=”35? height=”35? border=0></a></td>" +
                                       "<td><a href=\"https://twitter.com/Socioboard\" target=\"_blank\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/twitter-48_zps57c64c90.png\" alt=”Twitter” width=”35? height=”35? border=0></a></td>" +
                                       "</tr></table>";
                    }
                    else
                    {
                        logger.Error(result.Email + " " + result.RejectReason);
                        replysubject = "Request Not Recieved";
                        replybody    = "Hi there,</br>Oops!!</br>Apparently there was some error and we couldn’t receive your resume.</br>Please try again." +
                                       "<p>Best regards,<br />Support Team<br/>Socioboard Technologies Pvt. Ltd.<br /><a href=\"http://www.socioboard.com\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/logo-txt2_zpsc7861ad5.png\" alt=\"\"></a>" +
                                       "<br/></p><p style=\"font-family:Calibri(Body); font-size:12px;\"><b>Bangalore Office:</b> L V Complex, 2nd Floor, No.58, 7th Block, 80 Feet Road, Koramangala, Bangalore-560095</br>" +
                                       "Karnataka, India</br><b><br />Phone:</b> +91-90090-23807, <b>Skype:</b> socioboard.support </br><br />Socioboard Enterprise and SaaS Versions: <a href=\"http://www.socioboard.com\">http://www.socioboard.com<br />" +
                                       "</a>  Socioboard Community Version: <a href=\"http://www.socioboard.org\">http://www.socioboard.org</a><br></p><table><tr>" +
                                       "<td><a href=\"https://www.facebook.com/SocioBoard\" target=\"_blank\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/facebook-48_zps62d89d59.png\" alt=”Facebook” width=”35? height=”35? border=0></a></td>" +
                                       "<td><a href=\"https://plus.google.com/s/socioboard\" target=\"_blank\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/googleplus-30_zps62d89d59.png\" alt=\"G+\"width=”35? height=”35? border=0></a></td>" +
                                       "<td><a href=\"http://www.linkedin.com/company/socioboard\" target=\"_blank\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/linkedin-48_zpsceb0f4e2.png\" alt=”LinkedIn” width=”35? height=”35? border=0></a></td>" +
                                       "<td><a href=\"https://twitter.com/Socioboard\" target=\"_blank\"><img src=\"http://i739.photobucket.com/albums/xx33/Alan_Wilson3526/twitter-48_zps57c64c90.png\" alt=”Twitter” width=”35? height=”35? border=0></a></td>" +
                                       "</tr></table>";
                    }
                    string rtn = ReplyForCareerMail(to, replybody, replysubject, from, sendgridPassword);
                }

                sendMailByMandrill = "Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);

                sendMailByMandrill = ex.Message;
            }

            return(sendMailByMandrill);
        }
Exemplo n.º 22
0
        /// <summary>
        /// SendMailByMandrill
        /// this function is used for sending mail vai Mandrill</summary></summary>
        /// the main parameter is
        /// <add key="host" value="smtp.mandrillapp.com" />
        /// <param name="port"></param>
        /// <add key="port" value="25" />
        /// <param name="from"></param>
        /// <add key="username" value="socioboard"/>
        /// <param name="passsword"></param>
        /// <add key="fromemail" value="*****@*****.**"/>
        /// <param name="to"></param>
        /// <add key="password" value="xyz" />
        /// <param name="bcc"></param>
        /// add key="tomail" value="*****@*****.**" />
        /// its return : EmailResultStatus i.e Sent, Rejected etc.
        /// <param name="cc"></param>
        /// <param name="Host"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="sendgridUserName"></param>
        /// <param name="sendgridPassword"></param>
        /// <returns></returns>

        public string GetStatusFromSendMailByMandrill(string Host, int port, string from, string passsword, string to, string bcc, string cc, string subject, string body, string sendgridUserName, string sendgridPassword)
        {
            string sendMailByMandrill = string.Empty;

            try
            {
                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                //message.from_email = from;
                //message.from_name = from;//"AlexPieter";
                message.from_email = "*****@*****.**";
                message.from_name  = "Socioboard Support";
                message.html       = body;
                message.subject    = subject;
                message.to         = new List <Mandrill.EmailAddress>()
                {
                    new Mandrill.EmailAddress(to)
                };


                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(sendgridPassword, false);


                //List<RejectInfo> ri=mandrillApi.ListRejects();

                var    results = mandrillApi.SendMessage(message);
                string status  = string.Empty;
                foreach (var result in results)
                {
                    try
                    {
                        if (result.Status != Mandrill.EmailResultStatus.Sent)
                        {
                            logger.Error(result.Email + " " + result.RejectReason);
                        }

                        if (Mandrill.EmailResultStatus.Sent == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Sent.ToString();
                        }
                        else if (Mandrill.EmailResultStatus.Invalid == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Invalid.ToString();
                        }
                        else if (Mandrill.EmailResultStatus.Queued == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Queued.ToString();
                        }
                        else if (Mandrill.EmailResultStatus.Rejected == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Rejected.ToString();
                        }
                        else if (Mandrill.EmailResultStatus.Scheduled == result.Status)
                        {
                            status = Mandrill.EmailResultStatus.Scheduled.ToString();
                        }
                        else
                        {
                            status = result.RejectReason;
                        }
                        //status = Mandrill.EmailResultStatus;
                        //  LogManager.Current.LogError(result.Email, "", "", "", null, string.Format("Email failed to send: {0}", result.RejectReason));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        logger.Error(ex.Message);
                        sendMailByMandrill = ex.Message;
                    }
                }

                sendMailByMandrill = status;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                sendMailByMandrill = ex.Message;
            }

            return(sendMailByMandrill);
        }
Exemplo n.º 23
0
        public static void SendProgressBill(List <M.EmailAddress> argToAddress, string argCompany, string argProject, string argFlatNo, decimal argCurrentAmount, decimal argCurrentNetAmount, decimal argGross, decimal argNetAmount, decimal argPaidAmount, DataTable argdt)
        {
            try
            {
                //string activationLink = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Register/Activation.aspx?id=" + "";

                Cursor.Current = Cursors.WaitCursor;

                DataTable dt = new DataTable();
                dt = CommFun.GetMandrillSetting(1);
                if (dt == null)
                {
                    return;
                }
                if (dt.Rows.Count == 0)
                {
                    return;
                }

                string sFromName     = CommFun.IsNullCheck(dt.Rows[0]["FromName"], CommFun.datatypes.vartypestring).ToString();
                string sUserId       = CommFun.IsNullCheck(dt.Rows[0]["UserId"], CommFun.datatypes.vartypestring).ToString();
                string sKeyId        = CommFun.IsNullCheck(dt.Rows[0]["KeyId"], CommFun.datatypes.vartypestring).ToString();
                string sTemplateName = CommFun.IsNullCheck(dt.Rows[0]["TemplateId"], CommFun.datatypes.vartypestring).ToString();

                M.MandrillApi api = new M.MandrillApi(sKeyId, true);

                M.EmailMessage emailmsg = new M.EmailMessage();
                emailmsg.from_name    = sFromName;
                emailmsg.from_email   = sUserId;
                emailmsg.to           = argToAddress;
                emailmsg.attachments  = null;
                emailmsg.merge        = true;
                emailmsg.track_opens  = true;
                emailmsg.track_clicks = true;
                emailmsg.important    = true;

                emailmsg.AddGlobalVariable("Company", argCompany);
                emailmsg.AddGlobalVariable("Project", argProject);
                emailmsg.AddGlobalVariable("FlatNo", argFlatNo);
                emailmsg.AddGlobalVariable("PaidAmount", argPaidAmount.ToString("n2"));
                emailmsg.AddGlobalVariable("Balance", (argNetAmount - argPaidAmount).ToString("n2"));

                StringBuilder sb = new StringBuilder();
                sb.AppendLine("<table border='1' cellpadding='0' cellspacing='0'>");
                if (argdt != null)
                {
                    sb.Append("<tr>");
                    foreach (DataColumn column in argdt.Columns)
                    {
                        sb.AppendFormat("<td>{0}</td>", HttpUtility.HtmlEncode(column.ColumnName));
                    }
                    sb.Append("</tr>");

                    foreach (DataRow row in argdt.Rows)
                    {
                        sb.Append("<tr>");
                        foreach (DataColumn column in argdt.Columns)
                        {
                            sb.AppendFormat("<td>{0}</td>", HttpUtility.HtmlEncode(row[column]));
                        }
                        sb.Append("</tr>");
                    }
                }
                sb.AppendLine("</table>");

                emailmsg.AddGlobalVariable("StageDetails", sb.ToString());

                List <M.TemplateContent> tempContent = new List <M.TemplateContent>();
                tempContent.Add(new M.TemplateContent()
                {
                    name = sTemplateName
                });

                List <M.EmailResult> errorMsg = api.SendMessage(emailmsg, sTemplateName, tempContent);

                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 24
0
        public async Task<bool> SendAsync(EmailMessage email, bool deleteAttachmentes, params string[] attachments)
        {
            var config = this.Config as Config;

            if (config == null)
            {
                email.Status = Status.Cancelled;
                return false;
            }

            try
            {
                email.Status = Status.Executing;


                var message = new Mandrill.Models.EmailMessage();
                message.RawTo = email.SentTo.Split(',').ToList();
                message.FromEmail = email.FromEmail;
                message.FromName = email.FromName;
                message.Subject = email.Subject;
                if (email.IsBodyHtml)
                {
                    message.Html = email.Message;
                }
                else
                {
                    message.Text = email.Message;
                }
                message = AttachmentHelper.AddAttachments(message, attachments);
                var sendMessageRequest = new SendMessageRequest(message);

                var api = new MandrillApi(config.ApiKey);
                var result = await api.SendMessage(sendMessageRequest);

                var status = result.First().Status;
                // Verify
                if (status == Mandrill.Models.EmailResultStatus.Invalid || status == Mandrill.Models.EmailResultStatus.Rejected)
                {
                    email.Status = Status.Failed;
                }
                else if (status == Mandrill.Models.EmailResultStatus.Queued || status == Mandrill.Models.EmailResultStatus.Scheduled)
                {
                    email.Status = Status.Executing;
                }
                else if (status == Mandrill.Models.EmailResultStatus.Sent)
                {
                    email.Status = Status.Completed;
                }
                return true;
            }
            // ReSharper disable once CatchAllClause
            catch (Exception ex)
            {
                email.Status = Status.Failed;
                Log.Warning(@"Could not send email to {To} using SendGrid API. {Ex}. ", email.SentTo, ex);
            }
            finally
            {
                if (deleteAttachmentes)
                {
                    FileHelper.DeleteFiles(attachments);
                }
            }

            return false;
        }
Exemplo n.º 25
0
 public async Task<List<EmailResult>> SendEmails(EmailMessage em)
 {
     var mail = new MandrillApi(MailSettings.MandrillApi);
     return await mail.SendMessage(new SendMessageRequest(em));
 }
Exemplo n.º 26
0
        /// <summary>
        /// SendMailByMandrill
        /// this function is used for sending mail vai Mandrill for Enterprise Module</summary></summary>
        /// the main parameter is
        /// <add key="host" value="smtp.mandrillapp.com" />
        /// <param name="port"></param>
        /// <add key="port" value="25" />
        /// <param name="from"></param>
        /// <add key="username" value="socioboard"/>
        /// <param name="passsword"></param>
        /// <add key="fromemail" value="*****@*****.**"/>
        /// <param name="to"></param>
        /// <add key="password" value="xyz" />
        /// <param name="bcc"></param>
        /// add key="tomail" value="*****@*****.**" />
        /// its return : success if mail send else return string.Empty;
        /// <param name="cc"></param>
        /// <param name="Host"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="sendgridUserName"></param>
        /// <param name="sendgridPassword"></param>
        /// <returns></returns>
        public string SendMailByMandrillForEnterPrise(string name, string Host, int port, string from, string passsword, string to, string bcc, string cc, string subject, string body, string sendgridUserName, string sendgridPassword)
        {
            string sendMailByMandrill = string.Empty;
            try
            {

                Mandrill.EmailMessage message = new Mandrill.EmailMessage();
                //message.from_email = from;
                //message.from_name = from;//"AlexPieter";
                message.from_email = from;
                message.from_name = name;
                message.html = body;
                message.subject = subject;
                message.to = new List<Mandrill.EmailAddress>()
                {
                  new Mandrill.EmailAddress(to)
                };

                Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(sendgridPassword, false);
                var results = mandrillApi.SendMessage(message);

                foreach (var result in results)
                {
                    if (result.Status != Mandrill.EmailResultStatus.Sent)
                    {
                        logger.Error(result.Email + " " + result.RejectReason);
                    }
                    //  LogManager.Current.LogError(result.Email, "", "", "", null, string.Format("Email failed to send: {0}", result.RejectReason));
                }

                sendMailByMandrill = "success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                sendMailByMandrill = ex.Message;
            }

            return sendMailByMandrill;
        }