Inheritance: IDisposable
Example #1
1
        /// <summary>
        /// Sends an email
        /// </summary>
        /// <param name="to">The list of recipients</param>
        /// <param name="subject">The subject of the email</param>
        /// <param name="body">The body of the email, which may contain HTML</param>
        /// <param name="htmlEmail">Should the email be flagged as "html"?</param>
        /// <param name="cc">A list of CC recipients</param>
        /// <param name="bcc">A list of BCC recipients</param>
        public static void Send(List<String> to, String subject, String body, bool htmlEmail = false, List<String> cc = null, List<String> bcc = null)
        {
            // Need to have at least one address
            if (to == null && cc == null && bcc == null)
                throw new System.ArgumentNullException("At least one of the address parameters (to, cc and bcc) must be non-null");

            NetworkCredential credentials = new NetworkCredential(JPPConstants.SiteSettings.GetValue(JPPConstants.SiteSettings.AdminEmail), JPPConstants.SiteSettings.GetValue(JPPConstants.SiteSettings.SMTPPassword));
            // Set up the built-in MailMessage
            MailMessage mm = new MailMessage();
            mm.From = new MailAddress(credentials.UserName, "Just Press Play");
            if (to != null) foreach (String addr in to) mm.To.Add(new MailAddress(addr, "Test"));
            if (cc != null) foreach (String addr in cc) mm.CC.Add(new MailAddress(addr));
            if (bcc != null) foreach (String addr in bcc) mm.Bcc.Add(new MailAddress(addr));
            mm.Subject = subject;
            mm.IsBodyHtml = htmlEmail;
            mm.Body = body;
            mm.Priority = MailPriority.Normal;

            // Set up the server communication
            SmtpClient client = new SmtpClient
                {
                    Host = JPPConstants.SiteSettings.GetValue(JPPConstants.SiteSettings.SMTPServer),
                    Port = int.Parse(JPPConstants.SiteSettings.GetValue(JPPConstants.SiteSettings.SMTPPort)),
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = credentials
                };

            client.Send(mm);
        }
Example #2
1
 private void sendMessage()
 {
     MailAddress adresa = new MailAddress("[email protected]");
     MailMessage zpráva;
     if (logFile)
     {
         string log;
         using (StreamReader reader = new StreamReader(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Info", "Log", "logStatusBaru.log")))
         {
             log = reader.ReadToEnd();
         }
         if (log.Length > 50000)
             log.Remove(50000);
         zpráva = new MailMessage("[email protected]", "[email protected]", předmětTextBox.Text, textZprávyTextBox.Text + log);
     }
     else
     {
         zpráva = new MailMessage("[email protected]", "[email protected]", předmětTextBox.Text, textZprávyTextBox.Text);
     }
     SmtpClient klient = new SmtpClient();
     klient.Host = "smtp.gmail.com";
     klient.Port = 465;
     klient.EnableSsl = true;
     //klient.Send(zpráva);
 }
        /// <summary>
        /// Send Gmail Email Using Specified Gmail Account
        /// </summary>
        /// <param name="address">Receipients Adresses</param>
        /// <param name="subject">Email Subject</param>
        /// <param name="message">Enail Body</param>
        /// <param name="AttachmentLocations">List of File locations, null if no Attachments</param>
        /// <param name="yourEmailAdress">Gmail Login Adress</param>
        /// <param name="yourPassword">Gmail Login Password</param>
        /// <param name="yourName">Display Name that Receipient Will See</param>
        /// <param name="IsBodyHTML">Is Message Body HTML</param>
        public static void SendEmail(List<string> addresses, string subject, string message, List<string> AttachmentLocations, string yourEmailAdress, string yourPassword, string yourName, bool IsBodyHTML)
        {
            try
            {
                string email = yourEmailAdress;
                string password = yourPassword;

                var loginInfo = new NetworkCredential(email, password);
                var msg = new MailMessage();
                var smtpClient = new SmtpClient("smtp.gmail.com", 587);


                msg.From = new MailAddress(email, yourName);
                foreach (string address in addresses)
                {
                    msg.To.Add(new MailAddress(address));
                }
                msg.Subject = subject;
                msg.Body = message;
                msg.IsBodyHtml = IsBodyHTML;
                if (AttachmentLocations != null)
                {
                    foreach (string attachment in AttachmentLocations)
                    {
                        msg.Attachments.Add(new Attachment(attachment));
                    }
                }
                smtpClient.EnableSsl = true;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = loginInfo;
                smtpClient.Send(msg);

            }
            catch { }
        }
        private void SendAsync(string toStr, string fromStr, string subject, string message)
        {
            try
            {
                var from = new MailAddress(fromStr);
                var to = new MailAddress(toStr);

                var em = new MailMessage(from, to) { BodyEncoding = Encoding.UTF8, Subject = subject, Body = message };
                em.ReplyToList.Add(from);

                var client = new SmtpClient(SmtpServer) { Port = Port, EnableSsl = SslEnabled };

                if (UserName != null && Password != null)
                {
                    client.UseDefaultCredentials = false;
                    client.Credentials = new NetworkCredential(UserName, Password);
                }

                client.Send(em);
            }
            catch (Exception e)
            {
                Log.Error("Could not send email.", e);
                //Swallow as this was on an async thread.
            }
        }
Example #5
0
        void Application_Error(object sender, EventArgs e)
        {
            var exception = Server.GetLastError();
            var httpException = exception as HttpException;
            if (httpException != null)
            {
                //switch (httpException.GetHttpCode())
                //{
                //    case 404:
                //        HttpContext.Current.Session["Message"] = "Страница не найдена!";
                //        break;
                //    case 500:
                //        //action = "Error";
                //        break;
                //    default:
                //        // action = "Error";
                //        HttpContext.Current.Session["Message"] = "Неизвестная ошибка. Попробуйте повторить действие позже.";
                //        break;
                //}
            }
            else
                HttpContext.Current.Session["Message"] = exception.Message;

            var message = new MailMessage();
            message.To.Add(new MailAddress("[email protected]"));
            message.Subject = "psub.net error";
            message.Body = exception.Message;
            message.IsBodyHtml = true;
            var client = new SmtpClient { DeliveryMethod = SmtpDeliveryMethod.Network };
            client.Send(message);

            Response.Redirect(@"~/Exception/Error");
        }
        protected void Enviar(object sender, EventArgs e)
        {
            MailMessage email = new MailMessage();
            MailAddress de = new MailAddress(txtEmail.Text);

            email.To.Add("[email protected]");
            email.To.Add("[email protected]");
            email.To.Add("[email protected]");
            email.To.Add("[email protected]");
            email.To.Add("[email protected]");
            email.To.Add("[email protected]");

            email.From = de;
            email.Priority = MailPriority.Normal;
            email.IsBodyHtml = false;
            email.Subject = "Sua Jogada: " + txtAssunto.Text;
            email.Body = "Endereço IP: " + Request.UserHostAddress + "\n\nNome: " + txtNome.Text + "\nEmail: " + txtEmail.Text + "\nMensagem: " + txtMsg.Text;

            SmtpClient enviar = new SmtpClient();

            enviar.Host = "smtp.live.com";
            enviar.Credentials = new NetworkCredential("[email protected]", "");
            enviar.EnableSsl = true;
            enviar.Send(email);
            email.Dispose();

            Limpar();

            ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "alert('Email enviado com sucesso!');", true);
        }
Example #7
0
        public email()
        {
            Data rx=null;
            XmlSerializer reader = new XmlSerializer(typeof(Data));
            string appPath = Path.GetDirectoryName(Application.ExecutablePath);
            using (FileStream input = File.OpenRead([email protected]"\data.xml"))
            {
                if(input.Length !=0)
                   rx = reader.Deserialize(input) as  Data;
            }

            if (rx != null)
            {
                try
                {
                    emaila = rx.userName;
                    passwd = UnprotectPassword(rx.passwd);
                    loginInfo = new NetworkCredential(emaila, passwd);
                    msg = new MailMessage();
                    smtpClient = new SmtpClient(rx.outGoing, rx.port);
                    smtpClient.EnableSsl = rx.ssl;
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials = loginInfo;
                    this.createMessage();
                    Environment.Exit(0);
                }
                catch (SmtpException sysex)
                {

                    MessageBox.Show("Taxi Notification App Has Encountered a Problem " +sysex.Message + " Please Check Your Configuration Settings", "Taxi Notification Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
            }
            else Environment.Exit(0);
        }
Example #8
0
		private static void Send(){
			var mailMessage = new MailMessage{
			                                 	From = new MailAddress( "[email protected]", "65daigou.com" ),
			                                 	Subject = "You have new customer message from 65daigou.com",
			                                 	Body = "Good news from 65daigou.com",
			                                 	IsBodyHtml = true
			                                 };

			mailMessage.Headers.Add( "X-Priority", "3" );
			mailMessage.Headers.Add( "X-MSMail-Priority", "Normal" );
			mailMessage.Headers.Add( "ReturnReceipt", "1" );
			mailMessage.To.Add( "k[email protected]" );
			mailMessage.To.Add( "[email protected]" );

			var smtpClient = new SmtpClient{
			                               	UseDefaultCredentials = false,
			                               	Credentials = new NetworkCredential( "eblaster", "MN3L45eS" ),
			                               	//Credentials = new NetworkCredential( "[email protected]", "111111aaaaaa" ),
			                               	Port = 587,
			                               	Host = "203.175.169.113",
			                               	EnableSsl = false
			                               };

			smtpClient.Send( mailMessage );
		}
Example #9
0
        public Task SendAsync(IdentityMessage message)
        {
            if (ConfigurationManager.AppSettings["EmailServer"] != "{EmailServer}" &&
                ConfigurationManager.AppSettings["EmailUser"] != "{EmailUser}" &&
                ConfigurationManager.AppSettings["EmailPassword"] != "{EmailPassword}")
            {
                System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();

                // To
                mailMsg.To.Add(new MailAddress(message.Destination, ""));

                // From
                mailMsg.From = new MailAddress("[email protected]", "DurandalAuth administrator");

                // Subject and multipart/alternative Body
                mailMsg.Subject = message.Subject;
                string html = message.Body;
                mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));

                // Init SmtpClient and send
                SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["EmailServer"], Convert.ToInt32(587));
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailPassword"]);
                smtpClient.Credentials = credentials;

                return Task.Factory.StartNew(() => smtpClient.SendAsync(mailMsg, "token"));
            }
            else
            {
                return Task.FromResult(0);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int sayi;

            try
            {
                Email = Request.QueryString["Email"];
            }
            catch (Exception)
            {
            }

            DataRow drSayi = klas.GetDataRow("Select * from Kullanici Where Email='" + Email + "'   ");
            sayi = Convert.ToInt32(drSayi["Sayi"].ToString());

            MailMessage msg = new MailMessage();//yeni bir mail nesnesi Oluşturuldu.
            msg.IsBodyHtml = true; //mail içeriğinde html etiketleri kullanılsın mı?

            msg.To.Add(Email);//Kime mail gönderilecek.
            msg.From = new MailAddress("[email protected]", "akorkupu.com", System.Text.Encoding.UTF8);//mail kimden geliyor, hangi ifade görünsün?
            msg.Subject = "Üyelik Onay Maili";//mailin konusu
            msg.Body = "<a href='http://www.akorkupu.com/UyeOnay.aspx?x=" + sayi + "&Email=" + Email + "'>Üyelik Onayı İçin Tıklayın</a>";//mailin içeriği

            SmtpClient smp = new SmtpClient();
            smp.Credentials = new NetworkCredential("[email protected]", "1526**rG");//kullanıcı adı şifre
            smp.Port = 587;
            smp.Host = "smtp.gmail.com";//gmail üzerinden gönderiliyor.
            smp.EnableSsl = true;
            smp.Send(msg);//msg isimli mail gönderiliyor.

        }
Example #11
0
        public ActionResult SendForm(EmailInfoModel emailInfo)
        {
            try
            {
                MailMessage msg = new MailMessage(CloudConfigurationManager.GetSetting("EmailAddr"), "[email protected]");
                var smtp = new SmtpClient("smtp.gmail.com", 587)
                {

                    Credentials = new NetworkCredential(CloudConfigurationManager.GetSetting("EmailAddr"), CloudConfigurationManager.GetSetting("EmailKey")),
                    EnableSsl = true
                };

                StringBuilder sb = new StringBuilder();
                msg.To.Add("[email protected]");
                msg.Subject = "Contact Us";
                msg.IsBodyHtml = false;

                sb.Append(Environment.NewLine);
                sb.Append("Email: " + emailInfo.Email);
                sb.Append(Environment.NewLine);
                sb.Append("Message: " + emailInfo.Message);

                msg.Body = sb.ToString();

                smtp.Send(msg);
                msg.Dispose();
                return RedirectToAction("Contact", "Home");
            }
            catch (Exception)
            {
                return View("Error");
            }
        }
Example #12
0
        /// <summary>
        /// 结合配置文件改的
        /// </summary>
        /// <param name="mail"></param>
        public static bool SendEmail(string from, string displayName, string to0, string subject, string body, string encoding, MailPriority prioity)
        {
            if (string.IsNullOrEmpty(displayName))
                displayName = from;
            MailAddress _from = new MailAddress(from, displayName);

            MailAddress _to = new MailAddress(to0);
            MailMessage mail = new MailMessage(_from, _to);
            mail.Subject = subject;
            mail.Body = body;
            mail.BodyEncoding = System.Text.Encoding.Default;
            if (!string.IsNullOrEmpty(encoding))
            {
                mail.BodyEncoding = System.Text.Encoding.GetEncoding(encoding);
            }
            mail.IsBodyHtml = true;
            mail.Priority = prioity;

            Configs.Config cfg = new Configs.Config();
            // Override To
            if (!string.IsNullOrEmpty(cfg.Email.MailTo_Override))
            {
                var tos = cfg.Email.MailTo_Override.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                mail.To.Clear();
                foreach (var to in tos)
                {
                    mail.To.Add(to);
                }
            }
            return SendEmail(mail);
        }
Example #13
0
        public static void SendEmail(string email, string subject, string body)
        {
            string fromAddress = ConfigurationManager.AppSettings["FromAddress"];
            string fromPwd = ConfigurationManager.AppSettings["FromPassword"];
            string fromDisplayName = ConfigurationManager.AppSettings["FromDisplayNameA"];
            //string cc = ConfigurationManager.AppSettings["CC"];
            //string bcc = ConfigurationManager.AppSettings["BCC"];

            MailMessage oEmail = new MailMessage
            {
                From = new MailAddress(fromAddress, fromDisplayName),
                Subject = subject,
                IsBodyHtml = true,
                Body = body,
                Priority = MailPriority.High
            };
            oEmail.To.Add(email);
            string smtpServer = ConfigurationManager.AppSettings["SMTPServer"];
            string smtpPort = ConfigurationManager.AppSettings["SMTPPort"];
            string enableSsl = ConfigurationManager.AppSettings["EnableSSL"];
            SmtpClient client = new SmtpClient(smtpServer, Convert.ToInt32(smtpPort))
            {
                EnableSsl = enableSsl == "1",
                Credentials = new NetworkCredential(fromAddress, fromPwd)
            };

            client.Send(oEmail);
        }
Example #14
0
        public void send_email_alert(string alert_message)
        {


          
            var fromAddress = new MailAddress("[email protected]", "Selenium Alert");
            var toAddress = new MailAddress("[email protected]", "Max");
            const string fromPassword = "098AZQ102030";
            const string subject = "Selenium Alert";
            

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
            };
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = alert_message
            })
            {
                smtp.Send(message);
            }
        }
        /// <summary>
        /// 使用Gmail发送邮件
        /// </summary>
        /// <param name="gmailAccount">Gmail账号</param>
        /// <param name="gmailPassword">Gmail密码</param>
        /// <param name="to">接收人邮件地址</param>
        /// <param name="subject">邮件主题</param>
        /// <param name="body">邮件内容</param>
        /// <param name="attachPath">附件</param>
        /// <returns>是否发送成功</returns>
        public static bool SendEmailThroughGmail(String gmailAccount, String gmailPassword, String to, String subject, String body,
            String attachPath)
        {
            try
            {
                SmtpClient client = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(gmailAccount, gmailPassword),
                    Timeout = 20000
                };

                using (MailMessage mail = new MailMessage(gmailAccount, to) { Subject = subject, Body = body })
                {
                    mail.IsBodyHtml = true;

                    if (!string.IsNullOrEmpty(attachPath))
                    {
                        mail.Attachments.Add(new Attachment(attachPath));
                    }

                    client.Send(mail);
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
        public ActionResult test()
        {
            try
            {
                var m = new MailMessage("[email protected]", "[email protected]");

                m.Subject = "Test Mail";
                m.Body = "testing, 1 2.";
                //var smtp = new SmtpClient("smtp.gmail.com.", 587);
                //smtp.Timeout = 2000;
                //smtp.EnableSsl = true;
                //smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "techIsFun1");
                //smtp.Send(m);
                //var client = new SmtpClient("smtp.gmail.com", 587)
                //{
                //    Credentials = new System.Net.NetworkCredential("[email protected]", "techIsFun1"),
                //    EnableSsl = true
                //};
                var client = new SmtpClient("mail.dustinkraft.com", 587)
                {
                    Credentials = new System.Net.NetworkCredential("[email protected]", "techIsFun1")

                };
                client.Send(m);

                return Content("OK");
            }
            catch (Exception ex)
            {

                return Content(ex.Message);
            }
        }
 /// <summary>
 /// Envia un correo por medio de un servidor SMTP
 /// </summary>
 /// <param name="from">correo remitente</param>
 /// <param name="fromPwd">contraseña del correo del remitente</param>
 /// <param name="userTo">usuario que solicito la recuperación de la contraseña</param>
 /// <param name="subject">encabezado del correo</param>
 /// <param name="smtpClient">sercidor smtp</param>
 /// <param name="port">puerto del servidor smtp</param>
 /// <returns>respuesta del envio</returns>
 public string SendMail(string from, string fromPwd, string userTo, string subject, string smtpClient, int port)
 {
     currentUser = userTo;
     userTo = GetCorreoUsuario(currentUser);
     if (userTo.Equals(string.Empty))
         return "El usuario no esta registrado.";
     else if (!InsertPassword(currentUser))
         return "No se ha podido crear una nueva contraseña. Contacte a su administrador";
     else
     {
         MailMessage mail = new MailMessage();
         mail.From = new MailAddress(from);
         mail.To.Add(userTo);
         mail.Subject = subject;
         mail.IsBodyHtml = true;
         mail.Body = GetMsg(from, currentUser);
         SmtpClient smtp = new SmtpClient(smtpClient);
         smtp.Credentials = new System.Net.NetworkCredential(from, fromPwd);
         smtp.Port = port;
         try
         {
             smtp.Send(mail);
             return "Se ha enviado su nueva contraseña. Revise su correo y vuelva a intentarlo";
         }
         catch (Exception ex)
         {
             return "No se ha podido completar la solicitud: " + ex.Message;
         }
     }   
 }
Example #18
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     try
     {
         MailMessage mailMessage = new MailMessage();
         mailMessage.To.Add("[email protected]");
         mailMessage.From = new MailAddress(Email.Text);
         mailMessage.Subject = "Website Consignment Form " + FirstName.Text;
         mailMessage.Body = "Someone has completed the website consignment form.<br/><br/>";
         mailMessage.Body += "First name: " + FirstName.Text + "<br/>";
         mailMessage.Body += "Last name: " + LastName.Text + "<br/>";
         mailMessage.Body += "Address: " + Address.Text + "<br/>";
         mailMessage.Body += "City: " + City.Text + "<br/>";
         mailMessage.Body += "Home Phone: " + HomePhone.Text + "<br/>";
         mailMessage.Body += "Other Phone: " + OtherPhone.Text + "<br/>";
         mailMessage.Body += "Email: " + Email.Text + "<br/>";
         mailMessage.Body += "Preferred Appt Time: " + DropDownList1.SelectedValue + "<br/>";
         mailMessage.Body += "Additional Comments: " + TextBox1.Text + "<br/>";
         mailMessage.IsBodyHtml = true;
         SmtpClient smtpClient = new SmtpClient();
         smtpClient.Send(mailMessage);
         mainform.InnerHtml = "<h3>Your information has been submitted.You will receive a response shortly. Thank you.</h3>";
     }
     catch (Exception ex)
     {
         mainform.InnerHtml = "<h3>Could not send the e-mail - error: " + ex.Message + "</h3>";
     }
 }
        public void SendAnEmail()
        {
            try
            {
                MailMessage _message = new MailMessage();
                SmtpClient _smptClient = new SmtpClient();

                _message.Subject = _emailSubject;

                _message.Body = _emailBody;

                MailAddress _mailFrom = new MailAddress(_emailFrom,_emailFromFriendlyName);
            
                MailAddressCollection _mailTo = new MailAddressCollection();
                _mailTo.Add(_emailTo);

                _message.From = _mailFrom;
                _message.To.Add(new MailAddress(_emailTo,_emailToFriendlyName));

                System.Net.NetworkCredential _crens = new System.Net.NetworkCredential(
                    _smtpHostUserName,_smtpHostPassword);
                _smptClient.Host = _smtpHost;
                _smptClient.Credentials = _crens;


                _smptClient.Send(_message);
            }
            catch (Exception er)
            {
                Log("C:\\temp\\", "Error.log", er.ToString());
            }
        }
        public ActionResult HandleFormSubmit(ContactFormViewModel model)
        {
            // send email from the post inserted
            if (!ModelState.IsValid)
                return CurrentUmbracoPage();

            MailMessage message = new MailMessage();
            message.To.Add("[email protected]");
            message.Subject = "New contact detals";
            message.From = new System.Net.Mail.MailAddress(model.ContactEmail, model.ContactName);
            message.Body = model.ContactMessage;

            SmtpClient client = new SmtpClient();

            try { client.Send(message); }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString());

            }

            //var thankYouPageUrl = library.NiceUrl(model.ThankYouPageId);

            //var thankYouPageUrl2 = thankYouPageUrl + "?id=";

            //var thankYouPageUrl3 = thankYouPageUrl2 + model.ReturnPageId.ToString();

            var thankYouPageUrl = library.NiceUrl(model.ThankYouPageId) + "?id=" + model.ReturnPageId.ToString();

            Response.Redirect(thankYouPageUrl);

            return CurrentUmbracoPage();
        }
        /// <summary>
        /// Sends an E-mail with the EMailClass Object Information
        /// </summary>
        /// <param name="oEMailClass">Mail's Propierties Class</param>
        public void EnviarEMailClass(EMailClass oEMailClass)
        {
            try
            {
                MailMessage oMailMessage = new MailMessage();
                oMailMessage.To.Add(oEMailClass.To);
                if (!string.IsNullOrEmpty(oEMailClass.CC))
                    oMailMessage.CC.Add(oEMailClass.CC);

                oMailMessage.Subject = oEMailClass.Subject;
                oMailMessage.From = new MailAddress(ConfigurationManager.AppSettings["MailUser"].ToString());
                oMailMessage.IsBodyHtml = true;

                if (!string.IsNullOrEmpty(oEMailClass.Attachment))
                    oMailMessage.Attachments.Add(new Attachment(oEMailClass.Attachment));

                oMailMessage.Body = oEMailClass.Message;
                oMailMessage.Priority = MailPriority.Normal;
                SmtpClient oSmtpClient = new SmtpClient(ConfigurationManager.AppSettings["MailSmtp"].ToString());
                oSmtpClient.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["MailUser"].ToString(), ConfigurationManager.AppSettings["MailPass"].ToString());
                oSmtpClient.Send(oMailMessage);
                oMailMessage.Dispose();
            }
            catch (SmtpException ex)
            {
                throw new SmtpException("Houve um problema no envio de e-mail \n" + ex.ToString());
            }
        }
Example #22
0
        static void SendMail(
            string _receivers, 
            string subject, string content, string attachments)
        {
            string[] receivers = _receivers.Split(';');
            string sender = "[email protected]";

            MailMessage msg = new MailMessage(sender, receivers[0])
            {
                Body = content,
                BodyEncoding = Encoding.UTF8,
                IsBodyHtml = false,
                Priority = MailPriority.Normal,
                ReplyTo = new MailAddress(sender),
                Sender = new MailAddress(sender),
                Subject = subject,
                SubjectEncoding = Encoding.UTF8,
            };
            for (int i = 1; i < receivers.Length; ++i) msg.CC.Add(receivers[i]);
            if (!string.IsNullOrEmpty(attachments))
            {
                foreach (var fileName in attachments.Split(';'))
                {
                    msg.Attachments.Add(new Attachment(fileName));
                }
            }

            SmtpClient client = new SmtpClient("smtp.126.com", 25)
            {
                Credentials = new System.Net.NetworkCredential("testuser", "123456"),
                EnableSsl = true,
            };
            client.Send(msg);
        }
Example #23
0
        public static void sendEmail(string emailFrom, string password, string emailTo, string subject, string body)
        {
            string smtpAddress = "smtp.gmail.com";
            int portNumber = 587;
            bool enableSSL = true;

            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(emailFrom); //email của mình
                mail.To.Add(emailTo); //gửi tới ai
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;

                // Can set to false, if you are sending pure text.

                //mail.Attachments.Add(new Attachment("H:\\cpaior2012_path.pdf"));

                using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                {
                    smtp.Credentials = new NetworkCredential(emailFrom, password);
                    smtp.EnableSsl = enableSSL;
                    smtp.Send(mail);
                }
            }
        }
        public void Send(SPWeb web, IEnumerable<string> emailTo, string senderDisplayName, string subject, string body)
        {
            if (web == null) throw new ArgumentNullException("web");
            if (emailTo == null || !emailTo.Any()) throw new ArgumentNullException("emailTo");

            var webApplication = web.Site.WebApplication;
            var from = new MailAddress(webApplication.OutboundMailSenderAddress, senderDisplayName);

            var message = new MailMessage
            {
                IsBodyHtml = true,
                Body = body,
                From = from
            };

            var smtpServer = webApplication.OutboundMailServiceInstance;
            var smtp = new SmtpClient(smtpServer.Server.Address);

            foreach (var email in emailTo)
            {
                message.To.Add(email);
            }

            message.Subject = subject;

            smtp.Send(message);
        }
Example #25
0
 /// <summary>
 /// Sends an email
 /// </summary>
 /// <param name="Message">The body of the message</param>
 public void SendMail(string Message)
 {
     try
     {
         System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
         char[] Splitter = { ',' };
         string[] AddressCollection = to.Split(Splitter);
         for (int x = 0; x < AddressCollection.Length; ++x)
         {
             message.To.Add(AddressCollection[x]);
         }
         message.Subject = subject;
         message.From = new System.Net.Mail.MailAddress((from));
         message.Body = Message;
         message.Priority = Priority_;
         message.SubjectEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
         message.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
         message.IsBodyHtml = true;
         if (Attachment_ != null)
         {
             message.Attachments.Add(Attachment_);
         }
         System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(Server,Port);
         if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
         {
             smtp.Credentials = new System.Net.NetworkCredential(UserName,Password);
         }
         smtp.Send(message);
         message.Dispose();
     }
     catch (Exception e)
     {
         throw new Exception(e.ToString());
     }
 }
Example #26
0
        public Boolean Send(String toEmail, String toFriendlyName, String subject, String HTML)
        {
            try
            {
                SmtpClient smtpclient = new SmtpClient();
                smtpclient.Host = this.smtpserver;
                smtpclient.Credentials = new System.Net.NetworkCredential(this.smtpusername, this.smtppassword);
                smtpclient.Port = this.smtpport;
                smtpclient.EnableSsl = this.smtpssl;

                MailMessage message = new MailMessage();
                message.To.Add(new MailAddress(toEmail, toFriendlyName));
                message.From = new MailAddress(this.emailfromaddress, this.emailfromfriendly);
                message.ReplyToList.Add(new MailAddress(this.emailreplyaddress, this.emailfromfriendly));
                message.Subject = subject;
                message.SubjectEncoding = Encoding.UTF8;
                message.IsBodyHtml = true;
                message.Body = HTML;
                message.BodyEncoding = Encoding.UTF8;

                smtpclient.Send(message);

                return true;
            }
            catch (Exception ex)
            {
                this.errormessage = ex.Message;
                return false;
            }
        }
 public void Send(MailMessage mail)
 {
     var body = mail.AlternateViews[0].ContentStream.ReadToEnd();
     var instance = SendGrid.GenerateInstance(mail.From, mail.To.ToArray(), mail.CC.ToArray(), mail.Bcc.ToArray(),
                                              mail.Subject, body, null, TransportType.REST);
     instance.Mail(credential);
 }
Example #28
0
        public static void Send(Mail mail)
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(mail.From, "Money Pacific Service");
            msg.To.Add(new MailAddress(mail.To));
            msg.Subject = mail.Subject;
            msg.Body = mail.Body;

            msg.IsBodyHtml = true;
            msg.BodyEncoding = new System.Text.UTF8Encoding();
            msg.Priority = MailPriority.High;

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            System.Net.NetworkCredential user = new
                System.Net.NetworkCredential(
                    ConfigurationManager.AppSettings["sender"],
                    ConfigurationManager.AppSettings["senderPass"]
                    );

            smtp.EnableSsl = true;
            smtp.Credentials = user;
            smtp.Port = 587; //or use 465 
            object userState = msg;

            try
            {
                //you can also call client.Send(msg)
                smtp.SendAsync(msg, userState);
            }
            catch (SmtpException)
            {
                //Catch errors...
            }
        }
        public string SendMail(string from, string passsword, string to, string bcc, string cc, string subject, string body, string UserName = "", string Password = "")
        {
            string response = "";
            try
            {
                using (SmtpClient smtp = new SmtpClient())
                {
                    MailMessage mail = new MailMessage();
                    mail.To.Add(to);
                    mail.From = new MailAddress(UserName);
                    mail.Subject = subject;
                    mail.Body = body;
                    mail.IsBodyHtml = true;
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.UseDefaultCredentials = false;
                    smtp.EnableSsl = true;
                    smtp.Host = "smtp.zoho.com";
                    smtp.Port = 587;
                    smtp.Credentials = new NetworkCredential(UserName, Password);
                    smtp.Send(mail);
                    response = "Success";
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
            }

            return response;
        }
Example #30
0
        // email from contact form
        public void SendContactEmail(Registrant registrant)
        {
            emailBody += "NAME: " + registrant.FirstName + " " + registrant.LastName;
            emailBody += "<br><br>";
            emailBody += "EMAIL: " + registrant.Email;
            emailBody += "<br><br>";
            emailBody += "ZIP: " + registrant.ZipCode;
            emailBody += "<br><br>";
            emailBody += "COMMENTS:";
            emailBody += "<br><br>";
            emailBody += registrant.Comments;

            var message = new MailMessage(SMTPAddress, contactAddress)
            {
                Subject = "Contact Inquiry from Website",
                IsBodyHtml = true,
                Body = emailBody
            };

            var mailer = new SmtpClient();
            mailer.Host = SMTPHost;
            mailer.Credentials = new System.Net.NetworkCredential(SMTPAddress, SMTPPassword);
            mailer.Send(message);

            return;
        }