Send() public method

public Send ( MailMessage message ) : void
message MailMessage
return void
        public ActionResult HandleFormSubmit(ContactFormViewModel model)
        {
            // send email from the post inserted
            if (!ModelState.IsValid)
                return CurrentUmbracoPage();

            MailMessage message = new MailMessage();
            message.To.Add("*****@*****.**");
            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();
        }
Exemplo n.º 2
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);
        }
        public void ConfirmOrder(Order order)
        {
            if (order.Status != OrderStatus.Draft)
            {
                throw new InvalidOperationException("Only draft orders can be confirmed");
            }

            order.Status = OrderStatus.ReadyToShip;

            var smtpClient = new SmtpClient();

            // these emails would be much longer in practice and probably not hard coded!
            var confirmationEmail = new MailMessage(
                "*****@*****.**",
                order.Customer.Email,
                "Order confirmation: " + order.Code,
                "Hello there, Your order is confirmed and has gone off for processing");

            smtpClient.Send(confirmationEmail);

            var shipmentRequestEmail = new MailMessage(
                "*****@*****.**",
                OrderFulfilmentEmailAddress,
                "Order shipment request: " + order.Code,
                "Hello there, this order is confirmed. Please arrange shipment.");
            smtpClient.Send(shipmentRequestEmail);

            // maybe save order here as this would be typical procedural style (i.e. no persistence ignorance)
        }
Exemplo n.º 4
0
        public void Send(string @from, string to, string subject, string body, Stream stream = null,
                         string attachmentMimeType = null)
        {
            using (var client = new SmtpClient())
            {
                if (stream == null || attachmentMimeType == null)
                {
                    client.Send(@from, to, subject, body);
                }
                else
                {
                    if (string.IsNullOrEmpty(attachmentMimeType))
                    {
                        throw new ArgumentNullException();
                    }

                    //message
                    var mailMessage = new MailMessage(@from, to, subject, body);

                    //attachment
                    var attachment = new Attachment(stream, new ContentType(attachmentMimeType));
                    var disposition = attachment.ContentDisposition;
                    // Suggest a file name for the attachment.
                    disposition.FileName = ATTACHMENT_NAME;
                    // Add the attachment to the message.
                    mailMessage.Attachments.Add(attachment);
                    client.Send(mailMessage);
                }
            }
        }
 private void EmailConfirmations(CheckoutViewModel checkout)
 {
     var fromBody = string.Format("from {0} {1} at {2}", checkout.FirstName, checkout.LastName, checkout.Email);
     var settings = GetEmailSettings();
     using (
         var client = new SmtpClient(settings.Server, settings.Port)
         {
             Credentials = new NetworkCredential(settings.Username, settings.Password),
             EnableSsl = settings.EnableSsl
         })
     {
         if (!string.IsNullOrEmpty(checkout.Money))
         {
             client.Send(settings.From, settings.Money, "New Money Gift", string.Format("${0} {1}", checkout.Money, fromBody));
         }
         if (!string.IsNullOrEmpty(checkout.Time))
         {
             client.Send(settings.From, settings.Time, "New Time Gift", string.Format("{0} hours {1}", checkout.Time, fromBody));
         }
         if (!string.IsNullOrEmpty(checkout.Talent))
         {
             client.Send(settings.From, settings.Talent, "New Talent Gift", string.Format("{0} talent {1}", checkout.Talent, fromBody));
         }
         if (!string.IsNullOrEmpty(checkout.InKind))
         {
             client.Send(settings.From, settings.Time, "New In Kind Gift", string.Format("{0} in kind {1}", checkout.InKind, fromBody));
         }
         client.Send(settings.From, checkout.Email, settings.Subject, settings.Body);
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                mail = new MailMessage();
                SmtpServer = new SmtpClient("smtp.yourdomain.com");
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(combo.Items[combo.SelectedIndex].ToString());
                mail.Subject = subjbox.Text.ToString();
                mail.Body = msgbox.Text.ToString();
                if (strFileName != string.Empty)
                {
                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment(strFileName);
                    mail.Attachments.Add(attachment);

                    SmtpServer.Send(mail);
                    MessageBox.Show("Sent Message With Attachment", "MMS by Paul");
                }

                else {
                    SmtpServer.Send(mail);
                    MessageBox.Show("Sent Message", "MMS by Paul");
                     }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 7
0
        public static void SendEmail(EmailSenderData emailData)
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtpServer = new SmtpClient(emailData.SmtpClient);
            smtpServer.Port = 25;
            mail.From = new MailAddress(emailData.FromEmail);

            foreach (string currentEmail in emailData.Emails)
            {
                mail.To.Add(currentEmail);
            }
            mail.Subject = emailData.Subject;
            mail.IsBodyHtml = true;
            mail.Body = emailData.EmailBody;

            if (emailData.AttachmentPath != null)
            {                
                foreach (string currentPath in emailData.AttachmentPath)
                {
                    Attachment  attachment = new Attachment(currentPath);
                    mail.Attachments.Add(attachment);                    
                }               
                smtpServer.Send(mail);
                DisposeAllAttachments(mail);
            }
            else
            {
                smtpServer.Send(mail);
            }

            mail.Dispose();
            smtpServer.Dispose();
        }
        public void SendNotification(Notification notification, string message, ref string strError)
        {
            try
            {
                string email = string.Empty;
                string password = string.Empty;

                if (email == string.Empty || password == string.Empty)
                    throw new Exception("The email and password are not set for notifications");

                var client = new SmtpClient("smtp.gmail.com", 587)
                {
                    Credentials = new NetworkCredential(email, password),
                    EnableSsl = true
                };
                if (notification.NotificationType.ToUpper() == "EMAIL")
                    client.Send(email, notification.EmailAddress, "CryptoCoinControl Price Notification", message);
                else if (notification.NotificationType.ToUpper() == "SMS")
                    client.Send(email, notification.PhoneNumber + notification.CarrierGateway, string.Empty, message);
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
        }
Exemplo n.º 9
0
        public string EmailSend(StreamReader sr)
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(sr.ReadToEnd());
            XmlNode root = xDoc.DocumentElement;
            XmlNode emailNode = root.SelectSingleNode("EMAILID");
            XmlNode contactnumberNode = root.SelectSingleNode("CONTACTNUMBER");
            XmlNode messageNode = root.SelectSingleNode("MESSAGE");
            string emailId = (emailNode.InnerText);
            string contactnumber = (contactnumberNode.InnerText);
            string message = (messageNode.InnerText);

            var fromaddress = new MailAddress("*****@*****.**");
            var frompass = "******";
            var clientAdress = new MailAddress(emailId.ToString());
            var toAdress = new MailAddress("*****@*****.**");

            string subject = "Contact Mail from" + emailId;
            string body = "Message: " + message + "\n Contact Number: " + contactnumber + "\n from: <" + emailId + ">";

            string Usersubject = "Success Message";
            string Userbody = "Successfully Send message to TechGeek.org.in \n we will contact you as soon as possible \n Thanks.";
            try
            {
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient
                {

                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(fromaddress.Address, frompass)

                };

                using (var clientMessage = new MailMessage(fromaddress, clientAdress)
                {
                    Subject = Usersubject,
                    Body = Userbody
                })

                    smtp.Send(clientMessage);

                using (var Message = new MailMessage(fromaddress, toAdress)
                {
                    Subject = subject,
                    Body = body
                })

                    smtp.Send(Message);

               return "Send Data Successfully";
            }
            catch (Exception ex)
            {
                return ("Error" + ex.Message);
            }
        }
Exemplo n.º 10
0
        public void SendEmail(long batchControlLogID, string errorMessage)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug(string.Format("SendEmail({0},{1}", batchControlLogID, errorMessage));
            }

            if (!this.DoSendEmail)
            {
                return;
            }

            ArgumentCheck.ArgumentNullOrEmptyCheck(this.EmailRecipients, Constants.ERRORMESSAGE_EMAILRECIPIENTS);
            ArgumentCheck.ArgumentNullOrEmptyCheck(this.EmailSender, Constants.ERRORMESSAGE_EMAILSENDER);

            ////ArgumentCheck.ArgumentNullOrEmptyCheck(this.SMTPDomain, Constants.ERRORMESSAGE_SMTPDOMAIN);
            ////ArgumentCheck.ArgumentNullOrEmptyCheck(this.SMTPUser, Constants.ERRORMESSAGE_SMTPUSER);            
            ArgumentCheck.ArgumentNullOrEmptyCheck(this.SMTPPort, Constants.ERRORMESSAGE_SMTPPORT);
            ArgumentCheck.ArgumentNullOrEmptyCheck(this.SMTPServer, Constants.ERRORMESSAGE_SMTPSERVER);

            try
            {
                string errorSubject = null;
                string errorBody = null;
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    errorSubject = "Error Processing Payments ";
                    errorBody = errorMessage;
                }
                else if (batchControlLogID > 0)
                {
                    errorSubject = "Error Processing Payments, Batch ID: " + batchControlLogID.ToString();
                    errorBody = errorSubject;
                }

                MailMessage mail = new MailMessage(this.EmailSender, this.EmailRecipients, errorSubject, errorBody);

                SmtpClient smtpClient = new SmtpClient(this.SMTPServer, this.SMTPPort);
                smtpClient.UseDefaultCredentials = true;
                if (string.IsNullOrEmpty(this.SMTPEncryptedPassword) || string.IsNullOrEmpty(this.SMTPDomain) || string.IsNullOrEmpty(this.SMTPUser))
                {                   
                    smtpClient.Send(mail);
                }
                else
                {                    
                    string password = this.SMTPEncryptedPassword; // Decryptor.DecryptPassword(this.SMTPEncryptedPassword);
                    ImpersonateUser impersonateUser = new ImpersonateUser();
                    WindowsImpersonationContext impersonatedUser = impersonateUser.SetImpersonatedUser(this.SMTPUser, this.SMTPDomain, password);
                    {
                        smtpClient.Send(mail);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("SendEmail - {0}", ex.Message));                
            }
        }
Exemplo n.º 11
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            MailMessage sprocketToolsMessage = new MailMessage();
            sprocketToolsMessage.Subject = "Transaction email";
            sprocketToolsMessage.Body = "Test Transaction Email!";

            // Step 1a: Modify the POST string.
            string formPostData = "cmd = _notify-validate";
            foreach (String postKey in Request.Form)
            {
                string postValue = Encode(Request.Form[postKey]);
                formPostData += string.Format("&{0}={1}", postKey, postValue);
                sprocketToolsMessage.Body += (postKey + " : " + Request.Form[postKey] + System.Environment.NewLine);

            }

            // Step 1b: POST the data back to PayPal.
            WebClient client = new WebClient();
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            byte[] postByteArray = Encoding.ASCII.GetBytes(formPostData);
            byte[] responseArray = client.UploadData("https://www.paypal.com/cgi-bin/webscr", "POST", postByteArray);
            string response = Encoding.ASCII.GetString(responseArray);

            //message.IsBodyHtml = true;
            SmtpClient smtpClient = new SmtpClient();
            sprocketToolsMessage.From = new MailAddress("*****@*****.**");
            sprocketToolsMessage.To.Add("*****@*****.**");

            // Step 1c: Process the response from PayPal.
            switch (response)
            {
                case "VERIFIED":
                    {
                        // Perform steps 2-5 above.
                        // Continue with automation processing if all steps succeeded.
                        sprocketToolsMessage.Subject += " VERIFIED";

                        MailMessage customerEmail = new MailMessage();
                        customerEmail.IsBodyHtml = true;
                        customerEmail.Subject = "Sprocket Tools Order - " + Request.Form["txn_id"];
                        customerEmail.Body = "Thank you for your order!<br/><br/>  Please use the attachment to install your copy of " + Request.Form["item_name"];
                        FileStream fs = new FileStream(WSPMod.GetKeyedWsp(@"SprocketValidator.wsp", Request.Form["address_name"], "*", DateTime.Now.AddYears(100)), FileMode.Open);
                        Attachment a = new Attachment(fs,"SprocketValidator.wsp");
                        customerEmail.Attachments.Add(a);
                        smtpClient.Send(customerEmail);
                        break
                        ;
                    }
                default:
                    {
                        // Possible fraud. Log for investigation.
                        sprocketToolsMessage.Subject += " FRAUD";
                        break;
                    }
            }

            smtpClient.Send(sprocketToolsMessage);
        }
Exemplo n.º 12
0
 public string sendMail(string userdisplayname, string to, string from, string subject, string msg, string path)
 {
     string str = "";
     SmtpClient client = new SmtpClient
     {
         Credentials = new NetworkCredential(username, passwd),
         Port = port,
         Host = hostname,
         EnableSsl = true,
         DeliveryMethod = SmtpDeliveryMethod.Network,
         Timeout = 20000
     };
     this.mail = new MailMessage();
     string[] strArray = to.Split(new char[] { ',' });
     try
     {
         this.mail.From = new MailAddress(from, userdisplayname, Encoding.UTF8);
         for (byte i = 0; i < strArray.Length; i = (byte)(i + 1))
         {
             this.mail.To.Add(strArray[i]);
         }
         this.mail.Priority = MailPriority.High;
         this.mail.Subject = subject;
         this.mail.Body = msg;
         if (path != "")
         {
             LinkedResource item = new LinkedResource(path)
             {
                 ContentId = "Logo"
             };
             AlternateView view = AlternateView.CreateAlternateViewFromString("<html><body><table border=2><tr width=100%><td><img src=cid:Logo alt=companyname /></td><td>FROM BLUEFROST</td></tr></table><hr/></body></html>" + msg, null, "text/html");
             view.LinkedResources.Add(item);
             this.mail.AlternateViews.Add(view);
             this.mail.IsBodyHtml = true;
             this.mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
             this.mail.ReplyTo = new MailAddress(to);
             client.Send(this.mail);
             return str;
         }
         if (path == "")
         {
             this.mail.IsBodyHtml = true;
             this.mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
             this.mail.ReplyTo = new MailAddress(to);
             client.Send(this.mail);
             str = "good";
         }
     }
     catch (Exception exception)
     {
         if (exception.ToString() == "The operation has timed out")
         {
             client.Send(this.mail);
             str = "bad";
         }
     }
     return str;
 }
Exemplo n.º 13
0
        public static ReturnObject Submit(HttpContext context, string name, string email, string subject, string message)
        {
            var sb = new System.Text.StringBuilder();

            sb.AppendLine("<html><body>");
            sb.AppendLine("<b>Name</b>: " + name + "<br />");
            sb.AppendLine("<b>Email</b>: " + email + "<br />");
            sb.AppendLine("<b>Subject</b>: " + subject + "<br />");
            sb.AppendLine("<b>Message</b>:<br />" + message + "<br />");
            sb.AppendLine("</body></html>");

            //var msg = new System.Net.Mail.MailMessage("*****@*****.**", "*****@*****.**");
            var msg = new System.Net.Mail.MailMessage("*****@*****.**", "*****@*****.**");
            //var msg = new System.Net.Mail.MailMessage("*****@*****.**", "*****@*****.**");
            msg.IsBodyHtml = true;
            msg.Subject = "Contact Message from REMSLogic Webite";
            msg.Body = sb.ToString();

            var client = new System.Net.Mail.SmtpClient("relay-hosting.secureserver.net");
            //var client = new System.Net.Mail.SmtpClient("smtpout.secureserver.net");
            //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Safety1");
            //client.EnableSsl = false;
            client.Send(msg);

            sb = new System.Text.StringBuilder();

            sb.AppendLine("<html><body>");
            sb.AppendLine("Dear " + name + ",<br /><br />");
            sb.AppendLine("Thank you for your interest and for contacting us.<br /><br />");
            sb.AppendLine("<b>We will respond as soon as possible.</b><br />This website is in final development stages.<br /><br />");
            sb.AppendLine("</body></html>");

            msg = new System.Net.Mail.MailMessage("*****@*****.**", email);
            msg.IsBodyHtml = true;
            msg.Subject = "Thank you for contacting REMSLogic";
            msg.Body = sb.ToString();

            client.Send(msg);

            var ret = new ReturnObject()
            {
                Error = false,
                StatusCode = 200,
                Message = "Message sent successfully"
            };

            return ret;
        }
        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());
            }
        }
Exemplo n.º 15
0
        public void send_email_alert(string alert_message)
        {


          
            var fromAddress = new MailAddress("*****@*****.**", "Selenium Alert");
            var toAddress = new MailAddress("*****@*****.**", "Max");
            const string fromPassword = "******";
            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);
            }
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        public ActionResult SendForm(EmailInfoModel emailInfo)
        {
            try
            {
                MailMessage msg = new MailMessage(CloudConfigurationManager.GetSetting("EmailAddr"), "*****@*****.**");
                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("*****@*****.**");
                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");
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Send Gmail Email Using Specified Gmail Account
        /// </summary>
        /// <param name="address">Receipient Adress</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(string address, 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);
                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 { }
        }
Exemplo n.º 19
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     try
     {
         MailMessage mailMessage = new MailMessage();
         mailMessage.To.Add("*****@*****.**");
         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 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);
        }
Exemplo n.º 21
0
        static void SendMail(
            string _receivers, 
            string subject, string content, string attachments)
        {
            string[] receivers = _receivers.Split(';');
            string sender = "*****@*****.**";

            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);
        }
        public void Send_with_Auth_Success_Test()
        {
            using (var server = new SmtpServerForUnitTest(
                address: IPAddress.Loopback,
                port: 2525,
                credentials: new[] { new NetworkCredential("*****@*****.**", "p@$$w0rd") }))
            {
                server.Start();

                var client = new SmtpClient("localhost", 2525);
                client.Credentials = new NetworkCredential("*****@*****.**", "p@$$w0rd");
                client.Send(
                    "*****@*****.**",
                    "[email protected],[email protected]",
                    "[HELLO WORLD]",
                    "Hello, World.");

                server.ReceivedMessages.Count().Is(1);
                var msg = server.ReceivedMessages.Single();
                msg.MailFrom.Is("<*****@*****.**>");
                msg.RcptTo.OrderBy(_ => _).Is("<*****@*****.**>", "<*****@*****.**>");
                msg.From.Address.Is("*****@*****.**");
                msg.To.Select(_ => _.Address).OrderBy(_ => _).Is("*****@*****.**", "*****@*****.**");
                msg.CC.Count().Is(0);
                msg.Subject.Is("[HELLO WORLD]");
                msg.Body.Is("Hello, World.");
            }
        }
 /// <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;
         }
     }   
 }
Exemplo n.º 24
0
        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.
            }
        }
Exemplo n.º 25
0
        /// <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());
            }
        }
Exemplo n.º 26
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());
     }
 }
Exemplo n.º 27
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("*****@*****.**", "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("*****@*****.**", "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.

        }
Exemplo n.º 28
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);
                }
            }
        }
Exemplo n.º 29
0
		private static void Send(){
			var mailMessage = new MailMessage{
			                                 	From = new MailAddress( "*****@*****.**", "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( "*****@*****.**" );
			mailMessage.To.Add( "*****@*****.**" );

			var smtpClient = new SmtpClient{
			                               	UseDefaultCredentials = false,
			                               	Credentials = new NetworkCredential( "eblaster", "MN3L45eS" ),
			                               	//Credentials = new NetworkCredential( "*****@*****.**", "111111aaaaaa" ),
			                               	Port = 587,
			                               	Host = "203.175.169.113",
			                               	EnableSsl = false
			                               };

			smtpClient.Send( mailMessage );
		}
Exemplo n.º 30
0
        protected void Enviar(object sender, EventArgs e)
        {
            MailMessage email = new MailMessage();
            MailAddress de = new MailAddress(txtEmail.Text);

            email.To.Add("*****@*****.**");
            email.To.Add("*****@*****.**");
            email.To.Add("*****@*****.**");
            email.To.Add("*****@*****.**");
            email.To.Add("*****@*****.**");
            email.To.Add("*****@*****.**");

            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("*****@*****.**", "");
            enviar.EnableSsl = true;
            enviar.Send(email);
            email.Dispose();

            Limpar();

            ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "alert('Email enviado com sucesso!');", true);
        }
Exemplo n.º 31
0
        private void SendEmails()
        {
            string mailFrom = Convert.ToString("*****@*****.**");          //your own correct Gmail Address
            string password = Convert.ToString("pass123");
            string mailTo   = Convert.ToString("*****@*****.**"); //Email Address to whom you want to send the mail

            System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();
            email.To.Add(new System.Net.Mail.MailAddress(mailTo));
            email.From = new System.Net.Mail.MailAddress(mailFrom, "demo", System.Text.Encoding.UTF8);

            email.Subject         = "Subject";
            email.SubjectEncoding = System.Text.Encoding.UTF8;

            email.Body         = "Hi Deepak...";
            email.BodyEncoding = System.Text.Encoding.UTF8;
            email.Priority     = System.Net.Mail.MailPriority.High;

            //if (lblAttachment.Text.Length != 0)
            {
                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment(@"E:\\Demo\Hello.txt");
                email.Attachments.Add(attachment);
            }

            System.Net.Mail.SmtpClient Smtp = new System.Net.Mail.SmtpClient();
            Smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            Smtp.Credentials    = new System.Net.NetworkCredential(mailFrom, password); //Add the Creddentials- use your own email id and password
            Smtp.Port           = 587;                                                  // Gmail works on this port
            Smtp.Host           = "smtp.gmail.com";
            Smtp.EnableSsl      = true;                                                 //Gmail works on Server Secured Layer
            try
            {
                Smtp.Send(email);
                //lblSent.Text = "email has been sent successfully.";
                MessageBox.Text = "Email has been sent successfully...";
                //lblSent.Visible = true;
            }
            catch (Exception ex)
            {
                MessageBox.Text = ex.Message;
            }
        }
Exemplo n.º 32
0
        public void EnviarCorreo(String correoDestinatario, String asunto, String cuerpoMensaje)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            //a quien va dirigido

            msg.To.Add(correoDestinatario);

            msg.Subject         = asunto;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;

            //una copia a alguien adicional que deba recibir el correo
            //msg.Bcc.Add("aqui el correo");

            msg.Body         = cuerpoMensaje;
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.IsBodyHtml   = true;

            //quien está enviando el correo
            //msg.From = new System.Net.Mail.MailAddress("*****@*****.**");
            msg.From = new System.Net.Mail.MailAddress("*****@*****.**");

            System.Net.Mail.SmtpClient cliente = new System.Net.Mail.SmtpClient();

            //las credenciales de quien envia y se coloca el password

            //cliente.Credentials = new System.Net.NetworkCredential("*****@*****.**", "EPN123456");
            cliente.Credentials = new System.Net.NetworkCredential("*****@*****.**", "5109899555678");
            //a gmail

            cliente.Port      = 587;
            cliente.EnableSsl = true;
            cliente.Host      = "smtp.gmail.com"; //mail.dominio.com
            try
            {
                cliente.Send(msg);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //Console.ReadKey();
            }
        }
Exemplo n.º 33
0
        public void SendEmail(string to, string Subject, string body)
        {
            String prob          = " ";
            String complaint_idd = Session["comlaint_id"].ToString();
            String subject       = combProjectDesc.SelectedItem.Text + " issue of " + combprojCat.SelectedItem.Text
                                   + " From " + reported_channel.SelectedItem.Text + " ( Your Complaint Id is " + complaint_idd.ToString() + " ).";


            prob = txtRequestDes.Text;


            MailMessage message = new System.Net.Mail.MailMessage();

            message.To.Add(to);
            //message.CC.Add(cc);
            message.CC.Add("*****@*****.**");
            message.Subject = subject;
            message.From    = new System.Net.Mail.MailAddress("*****@*****.**");

            databaseDataContext data = new databaseDataContext();
            var user = (from u in data.UserManagers
                        where u.UserID.Equals(combAssignename.SelectedItem.Value)
                        select u
                        ).FirstOrDefault();

            message.Body = "Dear " + user.UserName.ToString() + ", \n\n "
                           + txtRequestDes.Text + "\n\nReported By:\n" + reported_by.Text
                           + "\n" + reports_email.Text + "\n\n Kindly check and resolve the issue.\n\n Thank you & Regards \n UBank \n\n\n This Email is Auto-Generated by Ubank IT Help Desk.";


            /* message.Body = "Dear " + user.UserName.ToString() + ", \n\n Issue Subject : " + subject + "\n\n Issue Description:-\n\t"
             + txtRequestDes.Text + "\n\n Please Login to resolve complaint." + "\n\n Reported By:\n\t" + reported_by.Text
             + "\n\t" + reports_email.Text + "\n\n Kindly check and resolve the issue.\n\n Thank you & Regards \n UBank IT Help Desk \n\n This Email is Auto-Generated by Ubank IT Help Desk.";
             */

            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["smtpServer"].ToString());
            smtp.Send(message);

            Response.Redirect("validation.aspx");

            //return true;
        }
Exemplo n.º 34
0
        private static string AssemblingeMail(string eMailTo, string eMailCC, string eMailBCC, string eMailForm, string eMailSubject, string eMailBody, string eMailFormat, System.Net.Mail.Attachment iCalendar)
        {
            string result = "Failed";

            try
            {
                System.Net.Mail.SmtpClient myMail = new System.Net.Mail.SmtpClient();
                myMail.Host = WebConfigurationManager.AppSettings["SMTPServer"];

                System.Net.Mail.MailMessage Mailmsg = new System.Net.Mail.MailMessage();

                Mailmsg.To.Clear();
                LoopAddress("mailTo", eMailTo, ref Mailmsg);
                LoopAddress("mailCC", eMailCC, ref Mailmsg);
                LoopAddress("mailBcc", eMailBCC, ref Mailmsg);
                LoopAddress("mailFrom", eMailForm, ref Mailmsg);

                Mailmsg.Attachments.Add(iCalendar);

                Mailmsg.Subject  = eMailSubject;
                Mailmsg.Priority = MailPriority.High;
                if (eMailFormat == "HTML")
                {
                    Mailmsg.IsBodyHtml = true;
                }
                Mailmsg.Body = eMailBody;

                try
                { myMail.Send(Mailmsg); }
                catch (Exception ex)
                {
                    string ms = ex.Message;
                }
                Mailmsg.Dispose();
                result = "Successfully";
            }
            catch
            {
                result = "Failed";
            }
            return(result);
        }
Exemplo n.º 35
0
        protected override async Task <IResponse> SendEmailAsync(IEmail email)
        {
            IResponse   res     = new Response();
            string      Subject = email.Subject;
            string      strBody = email.MailBody;
            MailMessage mail    = new MailMessage(email.From, email.To);

            mail.Subject = Subject;
            if (email.IsAttachment)
            {
                MemoryStream ms = new MemoryStream();
                ms.Write(email.pdfdata, 0, email.pdfdata.Length);
                ms.Position = 0;
                mail.Attachments.Add(new System.Net.Mail.Attachment(ms, "e-ticket_" + DateTime.UtcNow.ToString() + ".pdf"));
            }

            if (!string.IsNullOrWhiteSpace(email.Bcc))
            {
                mail.Bcc.Add(email.Bcc);
            }
            mail.IsBodyHtml = true;
            mail.Body       = strBody;
            try
            {
                using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(_settings.GetConfigSetting <string>(SettingKeys.Messaging.Email.AmazonSES.EmailHost), Convert.ToInt32(_settings.GetConfigSetting <string>((SettingKeys.Messaging.Email.AmazonSES.EmailPort)))))
                {
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new System.Net.NetworkCredential(_settings.GetConfigSetting <string>(SettingKeys.Messaging.Email.AmazonSES.HostUserName), _settings.GetConfigSetting <string>(SettingKeys.Messaging.Email.AmazonSES.HostUserPwd));
                    client.EnableSsl             = true;
                    client.Send(mail);
                }
                mail.Dispose();
                res.Success = true;
            }
            catch (Exception ex)
            {
                mail.Dispose();
                res.Success = false;
                _logger.Log(Logging.Enums.LogCategory.Error, ex);
            }
            return(res);
        }
Exemplo n.º 36
0
        //public async Task SendEmailAWS(string subject, string htmlBody, string textBody, List<string> recipients)
        //{
        //    await SendEmailFromClient(subject, htmlBody, recipients);

        //    using (var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.EUNorth1))
        //    {
        //        var sendRequest = new SendEmailRequest
        //        {
        //            Source = Constants.EmailSenderAddress,

        //            Destination = new Destination
        //            {
        //                ToAddresses = recipients
        //            },
        //            Message = new Message
        //            {

        //                Subject = new Content(subject),
        //                Body = new Body
        //                {
        //                    Html = new Content
        //                    {
        //                        Charset = "UTF-8",
        //                        Data = htmlBody
        //                    },
        //                    Text = new Content
        //                    {
        //                        Charset = "UTF-8",
        //                        Data = textBody
        //                    }
        //                }
        //            },
        //            // If you are not using a configuration set, comment
        //            // or remove the following line
        //            //ConfigurationSetName = configSet
        //        };
        //        try
        //        {
        //            Console.WriteLine("Sending email using Amazon SES...");
        //            var response = await client.SendEmailAsync(sendRequest);
        //            Console.WriteLine("The email was sent successfully.");
        //        }
        //        catch (Exception ex)
        //        {
        //            Console.WriteLine("The email was not sent.");
        //            Console.WriteLine("Error message: " + ex.Message);

        //        }
        //    }

        //}

        /*
         *  ses-smtp-user.20200505-212151
         * SMTP Username:
         * AKIAVDQTIQUA5BCTA7YB
         * SMTP Password:
         * BEKMmT7ECLgld436Gcfh54LRxD5u9VzsWuCqnZLK1oX3 */

        public bool SendEmailSMTP(string subject, string htmlBody, List <string> recipients)
        {
            MailMessage message = new MailMessage
            {
                IsBodyHtml = true,
                From       = new MailAddress(Constants.EmailSenderAddress),
                Subject    = subject,
                Body       = htmlBody
            };

            foreach (string recipient in recipients)
            {
                message.To.Add(new MailAddress(recipient));
            }

            // Comment or delete the next line if you are not using a configuration set
            //message.Headers.Add("X-SES-CONFIGURATION-SET", "ConfigSet");

            using (var client = new System.Net.Mail.SmtpClient(Constants.SmtpHost, Constants.SmtpPort))
            {
                // Pass SMTP credentials
                client.Credentials =
                    new NetworkCredential(Constants.SmtpUsername, Constants.SmtpPassword);
                // Enable SSL encryption
                client.EnableSsl = true;
                // Try to send the message. Show status in console.
                try
                {
                    Console.WriteLine("Attempting to send email...");
                    client.Send(message);
                    Console.WriteLine("Email sent!");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("The email was not sent.");
                    Console.WriteLine("Error message: " + ex.Message);
                    return(false);
                }

                return(true);
            }
        }
Exemplo n.º 37
0
        protected void sendMailCancelamentoTarefa(Tarefa tarefa)
        {
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            client.Host                  = "email-ssl.com.br";
            client.Port                  = 587;
            client.EnableSsl             = true;
            client.UseDefaultCredentials = false;
            client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "GCSti22.");
            MailMessage mail = new MailMessage();

            mail.Sender = new MailAddress("*****@*****.**", "GlobalCorps TI");
            mail.From   = new MailAddress("*****@*****.**", "GlobalCorps TI");
            mail.To.Add(new MailAddress(tarefa.Responsavel.Email, tarefa.Responsavel.Nome));
            mail.Subject = "NÃO RESPONDA - CONTROLE DE TAREFAS GLOBAL CORPORATE SOLUTIONS";
            mail.Body    =
                "<h3>A tarefa foi cancelada com sucesso!</h3>" +
                "<b>Titulo:</b> " + tarefa.Titulo +
                "<br/>" +
                "<b>Descricao:</b> " + tarefa.Descricao + "" +
                "<br/> " +
                "<b>Nivel Urgencia:</b> " + retornarNivelUrgencia(tarefa.NivelUrgencia) + "" +
                "<br/> " +
                "<b>Prazo:</b> " + tarefa.Prazo.Day + "/" + tarefa.Prazo.Month + "/" + tarefa.Prazo.Year +
                "<br/>" +
                "<b>Cancelado em:</b> " + tarefa.DataCancelamento.Day + "/" + tarefa.DataCancelamento.Month + "/" + tarefa.DataCancelamento.Year +
                "<br/><br/>" +
                "<h4>Acesse o sistema de controle de tarefas para mais informações!</h4>";
            mail.IsBodyHtml = true;
            mail.Priority   = MailPriority.High;
            try
            {
                client.Send(mail);
            }
            catch (System.Exception erro)
            {
                Console.WriteLine(erro);
            }
            finally
            {
                mail = null;
            }
        }
Exemplo n.º 38
0
        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            string msgTo      = tbe2.Text;
            string msgSubject = "We have received your Message ! ";
            string msgBody    = "Dear User," + tbe2.Text + " <br />" +
                                " You have received this email because you contacted us with a comment, question(s) and/or concerns.<br /><br />" +
                                "" +
                                " Our support staff will respond within next 48 hours.<br />" +
                                "Thank You.<br />" +
                                "Rapid Bill Pay Administration Team";

            MailMessage mailObj = new MailMessage();

            mailObj.Body = msgBody;
            mailObj.From = new MailAddress("*****@*****.**", "Rapid Bill Pay Admin Team");
            mailObj.To.Add(new MailAddress(msgTo));
            mailObj.Subject    = msgSubject;
            mailObj.IsBodyHtml = true;

            SmtpClient smtpClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);

            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "hameed@123");
            smtpClient.EnableSsl             = true;

            try
            {
                //smtpClient.Send("*****@*****.**",msgTo,"thanks subject",msgBody);
                smtpClient.Send(mailObj);
            }

            catch (Exception ex)
            {
                labelex.Text = ex.ToString();
            }
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Thank you for your message. An email has been send to the address you entered. Please feel free to contact us anytime in the future, so we will address your concerns');", true);

            tb1.Text       = "";
            tb2.Text       = "";
            tbe2.Text      = "";
            TextArea1.Text = "";
        }
Exemplo n.º 39
0
    protected void senmail()
    {
        User   use        = (User)Session["userobj"];
        string names      = name.Text;
        string ra         = radd.Text;
        string pa         = add.Text;
        string des        = items.Text;
        String msgTo      = use.EmailAddress;
        String msgSubject = "<Texans Store to door Delivary>Registration Conformation";
        string msgbody    = "Valued Customer  " + names;
        String msgBody    = "<br/>" + "<br/>" + "You have requested a new delivary.Details shown below." + "<br/>";

        msgBody += "Pickup Address : " + pa;
        msgBody += "<br/>" + "Recipient Address : " + ra;
        msgBody += "<br/>" + "Description : " + des;
        msgBody += "<br/>" + "Please note that any modifications made after 2 hours of submission of the original request shall be rejected." + "<br/>" + "<br/>" + "sincerely" +
                   "<Delivery service name> – Customer Service Team";

        string      msgbodyy = msgbody + msgBody;
        MailMessage mailObj  = new MailMessage();

        mailObj.Body = msgbodyy;
        mailObj.From = new MailAddress(use.EmailAddress, "We have recieved your email");
        mailObj.To.Add(new MailAddress(msgTo));
        mailObj.Subject    = msgSubject;
        mailObj.IsBodyHtml = true;
        SmtpClient SMTPClient = new System.Net.Mail.SmtpClient();

        SMTPClient.Host        = "smtp.gmail.com";
        SMTPClient.Port        = 587;
        SMTPClient.Credentials = new NetworkCredential("*****@*****.**", "vijayajanakisai");
        SMTPClient.EnableSsl   = true;
        try
        {
            SMTPClient.Send(mailObj);
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
                                                "err_msg",
                                                "alert('Email has been sent- Thank you');",
                                                true);
        }
        catch (Exception) { }
    }
    public void SendUserMail()
    {
        da = new SqlDataAdapter("select S_id from Registration where S_No=(select max (S_No) from Registration)", con);
        dt = new DataTable();
        da.Fill(dt);

        var          fromAddress  = "*****@*****.**";
        var          toAddress    = txtemailid.Text;
        const string fromPassword = "******";
        string       subject      = "user Registration Confirmation";
        string       body         = "Dear";

        body += "Name: " + txtname.Text + "\n";
        body += "Your Password Is Genrated by Admin";
        body += "User Sid: " + dt.Rows[0].ItemArray[0].ToString() + "\n";
        body += "Password: "******"\n";
        body += "Father's Name: " + txtfathername.Text + "\n";
        body += "DOB: " + txtdob.Text + "\n";
        body += "Address: " + txtaddress.Text + "\n";
        body += "Gender: " + ddlgender.SelectedItem.Text + "\n";
        body += "Email: " + txtemailid.Text + "\n";
        body += "Country: " + ddlcountry.SelectedItem.Text + "\n";
        body += "";
        body += "";
        body += "";
        body += "";
        body += "";
        body += "Thanks For Registration";
        var smtp = new System.Net.Mail.SmtpClient();

        {
            smtp.Host      = "smtp.gmail.com";
            smtp.Port      = 587;
            smtp.EnableSsl = true;
            // smtp.UserDefaultCredentials = false;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials    = new NetworkCredential(fromAddress, fromPassword);
            // smtp.timeout = 20000;
        }
        // passing values to smtp object
        smtp.Send(fromAddress, toAddress, subject, body);
    }
        public ActionResult ForgotPassword(string forgEmail)
        {
            int userId = PMS.BAL.UserBO.verifyEmail(forgEmail);

            if (userId > 0)
            {
                int         _min                = 1000;
                int         _max                = 9999;
                Random      _rdm                = new Random();
                int         code                = _rdm.Next(_min, _max);
                string      fromEmail           = "*****@*****.**";
                string      fromPass            = "******";
                string      fromName            = "PMS Admin";
                MailAddress fromAddress         = new MailAddress(fromEmail, fromName);
                MailAddress toAddress           = new MailAddress(forgEmail);
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(fromAddress.Address, fromPass)
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = "Reset Password",
                    Body = "Your code to reset Password is " + code.ToString(),
                })
                {
                    smtp.Send(message);
                }
                Session["code"] = Convert.ToString(code);
                Session["ID"]   = userId;
                return(View("CheckCode"));
            }
            else
            {
                ViewBag.MSG = "Email doesn't exist";
                return(View("Login"));
            }
        }
Exemplo n.º 42
0
        public void SendEmailDefault(string email, string subject, string textMessage)
        {
            MailMessage message = new MailMessage();

            message.IsBodyHtml = true;
            message.From       = new MailAddress("*****@*****.**", "Мой Email");
            message.To.Add(email);
            message.Subject = subject;
            message.Body    = textMessage;

            // message.Attachments.Add(new Attachment("..путь к файлу...."));
            using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com"))
            {
                client.Credentials = new NetworkCredential("*****@*****.**", "0971461796");
                client.Port        = 587;
                client.EnableSsl   = true;

                client.Send(message);
            }
        }
Exemplo n.º 43
0
        static void Main(string[] args)
        {
            // Criar o Email
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("Remetente");
            mail.To.Add(new MailAddress("Destinatário"));
            mail.Subject = "Ola mundo title!";
            mail.Body    = " Ola mundo body! ";

            using (var smtp = new System.Net.Mail.SmtpClient())
            {
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential("Email Remetente", "Senha Remetente");
                smtp.EnableSsl             = true;
                smtp.Send(mail);
            }
        }
Exemplo n.º 44
0
        public static bool SendMail(string message, string mailTo, string subject)
        {
            MailMessage ourMessage = new MailMessage();

            ourMessage.To.Add(mailTo);
            ourMessage.Subject = subject;
            ourMessage.From    = new System.Net.Mail.MailAddress("*****@*****.**");
            ourMessage.Body    = message;
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp-application.tp.edu.sg");
            try
            {
                smtp.Send(ourMessage);      // Send your mail.
                return(true);               // IF Mail sended Successfully
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);               // Send error
            }
        }
Exemplo n.º 45
0
        private static void Smtp()
        {
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
            client.EnableSsl   = true;
            client.Credentials = new NetworkCredential("*****@*****.**", "qqwwee11!!");

            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add("....");

            mail.Subject    = "Test smtp client";
            mail.Body       = "Hello";
            mail.IsBodyHtml = true;
            mail.Attachments.Add(new Attachment("D:\\1.jpg"));

            client.Send(mail);

            Console.WriteLine("OK");
        }
Exemplo n.º 46
0
        public IActionResult Details(Message entity)
        {
            var cls    = messageRepository.GetById(entity.MessageId);
            var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);

            client.UseDefaultCredentials = false;
            client.Credentials           = new NetworkCredential("*****@*****.**", "123VUKAT12");
            client.EnableSsl             = true;

            MailMessage mailMessage = new MailMessage();

            mailMessage.From = new MailAddress("*****@*****.**");
            mailMessage.To.Add(cls.Email);
            mailMessage.Body    = entity.Context;
            mailMessage.Subject = entity.Subject;

            client.Send(mailMessage);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 47
0
        public ActionResult TestMail()
        {
            System.Net.Mail.MailMessage mess = new System.Net.Mail.MailMessage();

            mess.From    = new MailAddress("*****@*****.**");
            mess.Subject = "test"; mess.Body = "test message";
            mess.To.Add("*****@*****.**");
            mess.To.Add("*****@*****.**");


            mess.SubjectEncoding = System.Text.Encoding.UTF8;
            mess.BodyEncoding    = System.Text.Encoding.UTF8;
            mess.IsBodyHtml      = true;
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("mx-votges-121.corp.gidroogk.com", 25);
            client.Credentials = new System.Net.NetworkCredential("ChekunovaMV", "320204", "CORP");

            // Отправляем письмо
            client.Send(mess);
            return(View());
        }
Exemplo n.º 48
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string body = "From:" + TextBox1.Text + "\n";

        body += "Subject:" + TextBox4.Text + "\n";
        body += "Message:" + TextBox5.Text + "\n";
        var smtp = new System.Net.Mail.SmtpClient();

        {
            smtp.Host           = "smtp.gmail.com";
            smtp.Port           = 587;
            smtp.EnableSsl      = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

            smtp.Credentials = new NetworkCredential(TextBox1.Text, TextBox2.Text);
            smtp.Timeout     = 20000;
        }
        smtp.Send(TextBox1.Text, DropDownList1.Text, TextBox4.Text, body);
        Label1.Text = "email is sent";
    }
Exemplo n.º 49
0
        //Send Mail through Smtp
        public void sendemail(string email, string subject, string body)
        {
            MailMessage message = new MailMessage();

            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
            message.From = new MailAddress(Configuration["Email"]);
            message.To.Add(new MailAddress(email));
            message.Subject    = subject;
            message.IsBodyHtml = true; //to make message body as html
            //BodyBuilder bodybuilder = new BodyBuilder();
            //bodybuilder.HtmlBody = body;//$"<h2>Here is the Confirmation Link</h2> <a></a>";
            message.Body               = body;
            smtp.Port                  = 587;
            smtp.Host                  = "smtp.gmail.com"; //for gmail host
            smtp.EnableSsl             = true;
            smtp.UseDefaultCredentials = true;
            smtp.Credentials           = new NetworkCredential(Configuration["Email"], Configuration["Password"]);
            smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
            smtp.Send(message);
        }
Exemplo n.º 50
0
        public Task SendAsync(IdentityMessage message)
        {
            MailMessage m = new System.Net.Mail.MailMessage(
                new MailAddress(ConfigurationManager.AppSettings["mailAdmin"], "Moodle"),
                new MailAddress(message.Destination))
            {
                Subject    = message.Subject,
                Body       = message.Body,
                IsBodyHtml = true
            };
            SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["mail"], 587);

            smtp.Credentials = new System.Net.NetworkCredential(
                ConfigurationManager.AppSettings["mailAdmin"],
                ConfigurationManager.AppSettings["mailPassword"]);
            smtp.EnableSsl = true;
            smtp.Send(m);

            return(Task.FromResult(0));
        }
Exemplo n.º 51
0
        /// <summary>
        /// Send a test email
        /// </summary>
        /// <param name="subject">Subject of the test email</param>
        private void SendTestEmail(string subject)
        {
            SystemEmail.SmtpClient client = new SystemEmail.SmtpClient();
            client.Port                  = 25;
            client.Host                  = "localhost";
            client.EnableSsl             = false;
            client.Timeout               = 60000;
            client.DeliveryMethod        = SystemEmail.SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials           = new System.Net.NetworkCredential(EmailConfig.GetUserName(), EmailConfig.GetPassword());

            SystemEmail.MailMessage message = new SystemEmail.MailMessage(EmailConfig.GetUserName(), EmailConfig.GetUserName(), subject, "test");
            message.BodyEncoding = UTF8Encoding.UTF8;
            message.Headers.Add("Message-Id", Guid.NewGuid().ToString());
            message.DeliveryNotificationOptions = SystemEmail.DeliveryNotificationOptions.OnFailure;

            client.Send(message);

            Thread.Sleep(5000);
        }
Exemplo n.º 52
0
        public static void SendEmail(string from, List <string> to, List <string> cc, string subject, string body, System.Net.Mail.SmtpClient smtp)
        {
            MailMessage EmailMsg = new MailMessage();

            EmailMsg.From = new MailAddress(from);
            foreach (string s in to)
            {
                EmailMsg.To.Add(new MailAddress(s));
            }
            foreach (string c in cc)
            {
                EmailMsg.CC.Add(new MailAddress(c));
            }
            EmailMsg.Subject    = subject;
            EmailMsg.Body       = body;
            EmailMsg.IsBodyHtml = true;
            EmailMsg.Priority   = MailPriority.Normal;

            smtp.Send(EmailMsg);
        }
Exemplo n.º 53
0
        public void NewHeadlessEmail(string fromEmail, string password, string toAddress, string subject, string body)
        {
            using (System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage())
            {
                myMail.From = new MailAddress(fromEmail);
                myMail.To.Add(toAddress);
                myMail.Subject    = subject;
                myMail.IsBodyHtml = true;
                myMail.Body       = body;

                using (System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587))
                {
                    s.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    s.UseDefaultCredentials = false;
                    s.Credentials           = new System.Net.NetworkCredential(myMail.From.ToString(), password);
                    s.EnableSsl             = true;
                    s.Send(myMail);
                }
            }
        }
Exemplo n.º 54
0
        public void Execute()
        {
            using (MemoryStream attachment = new MemoryStream())
            {
                this.PdfDoc.Save(attachment, false);
                attachment.Position = 0;

                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
                client.EnableSsl             = true;
                client.UseDefaultCredentials = false;
                client.Credentials           = new NetworkCredential(this.EmailAddress, this.EmailPassword);
                client.DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network;
                client.Timeout = 60000;

                MailMessage mm = new MailMessage(this.EmailAddress, this.EmailAddress);
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mm.Attachments.Add(new Attachment(attachment, "untitled.pdf", System.Net.Mime.MediaTypeNames.Application.Pdf));
                client.Send(mm);
            }
        }
Exemplo n.º 55
0
        public static void SendWithAttachment(MailAddress fromAddress, MailAddress toAddress, string fromPassword, string subject, string body, Attachment attachment, string filePath)
        {
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
            };
            var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body    = body
            };

            message.Attachments.Add(attachment);
            smtp.Send(message);
        }
Exemplo n.º 56
0
Arquivo: Mail.cs Projeto: zggcd/ITT
        public static void SendNetMail(string to, string from, string name, string subject, string body)
        {
            try
            {
                System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
                myMail.From = new System.Net.Mail.MailAddress(from, name);
                myMail.To.Add(to);
                myMail.Subject      = subject;
                myMail.IsBodyHtml   = true;
                myMail.Body         = body;
                myMail.BodyEncoding = System.Text.Encoding.UTF8;

                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
                smtp.Send(myMail);
            }
            catch (Exception ex)
            {
                HL.Lib.Global.Error.Write("SendNetMail", ex);
            }
        }
Exemplo n.º 57
0
        /// <summary>
        /// Sends a message to an SMTP server for delivery.
        /// </summary>
        /// <param name="subject">The subject line for this e-mail message.</param>
        /// <param name="body">The message body for this e-mail message.</param>
        private static void DotNetMailSendMessage(string subject, string body)
        {
            using (DotNetMail.SmtpClient client = new DotNetMail.SmtpClient())
            {
                client.Port                  = 587;
                client.Host                  = "smtp.gmail.com";
                client.EnableSsl             = true;
                client.DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials           = new System.Net.NetworkCredential(from.Address, password);

                using (DotNetMail.MailMessage message = new DotNetMail.MailMessage(from, to)
                {
                    Subject = subject, Body = body
                })
                {
                    client.Send(message);
                }
            }
        }
Exemplo n.º 58
0
        public static bool SendEmail(Email mailer)
        {
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            using (System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage()) {
                bool bOut = false;
                if (!String.IsNullOrEmpty(mailer.ToList))
                {
                    string[] toList = mailer.ToList.Split(';');
                    foreach (string to in toList)
                    {
                        message.To.Add(new MailAddress(to));
                    }
                }
                if (!String.IsNullOrEmpty(mailer.CcList))
                {
                    string[] ccList = mailer.CcList.Split(';');
                    foreach (string cc in ccList)
                    {
                        message.CC.Add(new MailAddress(cc));
                    }
                }

                message.Subject    = mailer.Subject;
                message.IsBodyHtml = mailer.IsHTML;
                message.Body       = mailer.MessageBody;
                try {
                    client.Send(message);
                    //TODO: CMC - log this
                    bOut = true;
                }
                catch (System.Net.Mail.SmtpException x)
                {
                    LovRubLogger.LogException(x); // KPL added 04/10/08
                    throw x;
                    //TODO: CMC - Log Exception, Do we really want to throw this back up the stack?
                    //throw new Exception("Email not sent: " + x.Message + "; message details: " + message.ToString());
                    //log this
                }
                return(bOut);
            }
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
        User user = ConnectionClass.GetUserByName(TextBox1.Text);

        if (user == null)
        {
            Label1.Text = "User not found";
        }
        else
        {
            string email = user.Email;
            try
            {
                var          to       = email;
                var          from     = "*****@*****.**";
                const string password = "******";
                string       subject  = "Consultancy House Client Login Password Recovery for :" + user.UserName;
                string       body     = " Consultancy House Login \n Password Recovery\n";
                body += "Your login Credentials : \n";
                body += "Username: "******"\n";
                body += "Password: "******"\n\n";
                body += "If any query please reply on this same mail";
                var smtp = new System.Net.Mail.SmtpClient();
                {
                    smtp.Host           = "smtp.gmail.com";
                    smtp.Port           = 587;
                    smtp.EnableSsl      = true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Credentials    = new NetworkCredential(from, password);
                    smtp.Timeout        = 20000;
                }

                smtp.Send(from, to, subject, body);
                Label1.Text   = "Request for Password Recovery successfully submitted.We'll shortly contact you at your registered email.";
                TextBox1.Text = "";
            }
            catch (Exception)
            {
            }
        }
    }
Exemplo n.º 60
0
        public static Boolean SendEmail(String toEmailAddress, String subject, String body)
        {
            try
            {
                String SMTPServer   = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"];
                String SMTPPort     = System.Configuration.ConfigurationManager.AppSettings["SMTPPort"];
                String UserLogin    = System.Configuration.ConfigurationManager.AppSettings["SMTPUser"];
                String UserPassword = System.Configuration.ConfigurationManager.AppSettings["SMTPPassword"];

                String fromEmailAddress = System.Configuration.ConfigurationManager.AppSettings["FromAddress"];

                String      fromDisplayName = "Student Request Portal";
                MailAddress fromAddress     = new MailAddress(fromEmailAddress, fromDisplayName);

                MailAddress toAddress = new MailAddress(toEmailAddress);

                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient
                {
                    Host                  = SMTPServer,
                    Port                  = Convert.ToInt32(SMTPPort),
                    EnableSsl             = true,
                    DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(UserLogin, UserPassword)
                };

                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    smtp.Send(message);
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }