How to send email from Asp.net Mvc-3?

后端 未结 9 1675
太阳男子
太阳男子 2020-12-23 09:50

How to send a mail through mvc-3 asp.net using c#?

I have to send a forgot password so how can I do this? My code is below.

Model code..

 usi         


        
相关标签:
9条回答
  • 2020-12-23 10:34

    you can use this...

        public void SendEmail(string address, string subject, string message)
        {
            string email = "-your-id-@gmail.com";
            string password = "put-your-GMAIL-password-here";
    
            var loginInfo = new NetworkCredential(email, password);
            var msg = new MailMessage();
            var smtpClient = new SmtpClient("smtp.gmail.com", 587);
    
            msg.From = new MailAddress(email);
            msg.To.Add(new MailAddress(address));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = true;
    
            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = loginInfo;
            smtpClient.Send(msg);
        }
    
    0 讨论(0)
  • 2020-12-23 10:35

    i am using this for sending email, in ASP.net MVC3

    System.Web.Helpers.WebMail.SmtpServer = smtp_server;
                System.Web.Helpers.WebMail.SmtpPort = smtp_port;
                System.Web.Helpers.WebMail.EnableSsl = true;
                System.Web.Helpers.WebMail.From = "fromaddress";
                StringBuilder sb = new StringBuilder();
                sb.Append("<table><tr><td>");            
                sb.Append(msg);                     
                sb.Append("</td></tr></table>");
                string body = sb.ToString();
                string To = toemail;
                System.Web.Helpers.WebMail.Send(To,subject, body);
    
    0 讨论(0)
  • 2020-12-23 10:36

    Have a look at MvcMailer

    MvcMailer provides you with an ActionMailer style email sending NuGet Package for ASP.NET MVC 3/4. So, you can produce professional looking emails composed of your MVC master pages and views with ViewBag.

    0 讨论(0)
提交回复
热议问题