如何在ASP .NET MVC 5中记录Gmail [英] How to log Gmail in ASP .NET MVC 5

查看:90
本文介绍了如何在ASP .NET MVC 5中记录Gmail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我登录到我的WebApplication时,我想也会自动登录到Gmail。完全像我会去gmail.com并自己输入我的电子邮件地址和密码。

它必须在客户端完成,因此必须使用Java Script。让我们作一个前提,我们已经知道登录名和密码:

 函数LoginGmail(登录名,密码){


问题:如何通过Java脚本登录Gmail?

解决方案

我无法清楚地理解您的问题,但我认为您希望通过C#代码向某人发送电子邮件。这是您可以使用的代码。

  SmtpClient client = new SmtpClient(); 
MailMessage msg = new MailMessage();
MailAddress to =新MailAddress(客户电子邮件地址);
MailAddress from =新MailAddress(您的电子邮件地址);
msg.IsBodyHtml = true;
msg.Subject =邮件标题;
msg.To.Add(to);
msg.Body =您的信息;
msg.From = from;
client.Send(msg);

在配置部分的web.config文件中,您需要编写邮件帐户的凭证信息

 < system.net> 
< mailSettings>
< smtp deliveryMethod =网络>
< / smtp>
< / mailSettings>
< /system.net>


When I log into my WebApplication i would like to be also automatically logged into Gmail. Exactly like I would go to gmail.com and typed my e-mail address and password myself.

It has to be done on client's side thus one must use Java Script. Let's make a premiss that we already know login and password:

 function LoginGmail(login, password) {

    }

Question: How to login to Gmail via Java Script?

解决方案

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>

这篇关于如何在ASP .NET MVC 5中记录Gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆