How to use gmail SMTP in ASP.NET form

前端 未结 7 600
眼角桃花
眼角桃花 2020-12-04 02:00

I am a ASP novice and am troubleshooting a form for work. None of us here are ASP experts as we use PHP. But I am on the bottom of PHP experience as well, mostly working wit

7条回答
  •  失恋的感觉
    2020-12-04 02:46

    Create a System.Net.Mail.SmtpClient object, set the SMTP server info you are using.

    Then create a System.Smtl.MailMessage with the message data and send it:

    using (System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient()) {
        using (System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("from*where.com", "to@where.com") {
            IsBodyHtml = true,
            Subject = "Subject text",
            Body = messageBody,
        }) {
            mail.Send(message);
    } // using
    

    You can configure your SmtpClient in the constructor, we use web.comfig, so I don't have that code.

提交回复
热议问题