How to log Gmail in ASP .NET MVC 5 [closed]

别说谁变了你拦得住时间么 提交于 2019-12-04 22:09:17

I could not get your question clearly but what I think is that you want to send an email to someone by C# code. Here is the code which you can use.

SmtpClient client = new SmtpClient();
            MailMessage msg = new MailMessage();                
            MailAddress to = new MailAddress("client email address");
            MailAddress from = new MailAddress("Your Email Address");
            msg.IsBodyHtml = true;
            msg.Subject = "Mail Title";
            msg.To.Add(to);
            msg.Body = "Your message";
            msg.From = from;
            client.Send(msg);

In web.config file under configuration section, you need to write the credential information of your mail account

    <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com" port="587" userName="your email address" password="your password" defaultCredentials="false" enableSsl="true" />
      </smtp>
    </mailSettings>
  </system.net>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!