Problems sending e-mail in web app

前端 未结 3 1666
悲哀的现实
悲哀的现实 2021-01-28 20:27

I have been trying for 2 days to get my ASP.NET webforms application to send an e-mail.

I have tried this using both outlook and gmail. I got the smtp information for bo

3条回答
  •  鱼传尺愫
    2021-01-28 20:59

    public  void sendEmail(string body)
        {
            if (String.IsNullOrEmpty(email))
                return;
            try
            {
                MailMessage mail = new MailMessage();
                mail.To.Add(email);
                mail.To.Add("xxx@gmail.com");
                mail.From = new MailAddress("yyy@gmail.com");
                mail.Subject = "sub";
    
                mail.Body = body;
    
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
                smtp.Credentials = new System.Net.NetworkCredential
                     ("yyy@gmail.com", "pw"); // ***use valid credentials***
                smtp.Port = 587;
    
                //Or your Smtp Email ID and Password
                smtp.EnableSsl = true;
                smtp.Send(mail);
            }
            catch (Exception ex)
            {
                print("Exception in sendEmail:" + ex.Message);
            }
        }``
    

    http://www.c-sharpcorner.com/UploadFile/47548d/how-to-send-bulk-email-using-Asp-Net/

提交回复
热议问题