- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用简单的 CMD“服务”扩展我的 Web 应用程序,它应该向新注册的用户发送验证电子邮件。我的问题是通过验证 Gmail 帐户,抛出以下异常:
“SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。”
我已经尝试在我自己的 IMAP 服务器上进行身份验证,但也没有成功。后来我尝试使用XAMP Mercury邮件服务器,这不是最好的解决方案,由于完全依赖本地配置,所以我放弃了那个想法。将来,我只想为应用程序创建一个新的谷歌帐户,因此不需要维护。
String body = "<head>" +
"Here comes some logo" +
"</head>" +
"<body>" +
"<h1>Account confirmation reqest.</h1>" + Environment.NewLine +
"<a>Dear User, </a>" + Environment.NewLine +
"<a>In order to be able to use musicshop app properly, we require You to confirm Your email address.</a>" + Environment.NewLine +
"<a>This is the last step towards using our app.</a>" + Environment.NewLine +
"<a>Pleas follow this hyperlink to confirm your address.</a>" + Environment.NewLine +
"<a>[Callback url]</a>" +
"</body>";
try
{
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential()
{
UserName = "myemail@gmail.com",
Password = "mypassword"
};
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
smtpClient.Send("targetemail@targetdomain.xyz", "myemail@gmail.com", "Account verification", body);
}
catch (Exception ex)
{
}
我只想能够通过 Gmail 服务器发送电子邮件,没有任何异常(exception)。我是否需要为此使用任何 NuGet 包,使用不同的方法?
最佳答案
如果您的 Gmail 帐户启用了两步验证,您将必须创建一个 App-Specific Password代替进行身份验证。
另请注意,SmtpClient 是 IDisposable
- 您应该将其放入 using (var smtpClient = new SmtpClient("smtp.gmail.com", 587)) { ...
阻止 SMTP 连接 RSET、QUIT 和正确关闭。
== 编辑 ==
此外,您似乎在 smtpClient.Send
上切换了 from
和 recipients
参数。
string body = "<head>" +
"Here comes some logo" +
"</head>" +
"<body>" +
"<h1>Account confirmation reqest.</h1>" + Environment.NewLine +
"<a>Dear User, </a>" + Environment.NewLine +
"<a>In order to be able to use musicshop app properly, we require You to confirm Your email address.</a>" + Environment.NewLine +
"<a>This is the last step towards using our app.</a>" + Environment.NewLine +
"<a>Pleas follow this hyperlink to confirm your address.</a>" + Environment.NewLine +
"<a>[Callback url]</a>" +
"</body>";
try
{
using (var smtpClient = new SmtpClient("smtp.gmail.com", 587))
{
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential()
{
UserName = Config.Username,
Password = Config.Password,
};
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
//Oops: from/recipients switched around here...
//smtpClient.Send("targetemail@targetdomain.xyz", "myemail@gmail.com", "Account verification", body);
smtpClient.Send("myemail@gmail.com", "targetemail@targetdomain.xyz", "Account verification", body);
}
}
catch (Exception e)
{
Console.Error.WriteLine("{0}: {1}", e.ToString(), e.Message);
}
关于C#通过Gmail账户发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57644814/
我有一个英国 PayPal 企业帐户。我目前正在开发一个网站支付系统,使用 Express Checkout 向这个账户付款。 到目前为止,我的 PHP 代码正在运行,我能够连接到沙箱并设置和快速结帐
如何使用自定义消息和自定义 from 参数而不是默认参数向用户发送电子邮件验证。 Meteor.methods({ sendveryficationmail: function (theuse
考虑一个场景,其中他们是 PartyA,并且 account1 是在 PartyA 中创建的。现在我们要在account1和PartyA之间发起一笔交易。是否可以有一个由账户发起、接收方为主机节点的交
我有多个 AWS 账户,根据我所在的项目目录,我想在 AWS CLI 中键入命令时使用不同的账户。 我知道 AWS 凭据可以通过环境变量传递,所以我认为一种解决方案是根据它所在的目录设置 AWS_CO
我希望能够使用 PayPal Mass Payment 向我网站的用户付款。如果他们有 PayPal 帐户,我认为这非常简单。 但是,如果他们没有 PayPal 帐户,有没有办法让他们通过我的网站注册
是否可以使用 paypal API 向任何 paypal 帐户(不仅仅是 API 凭据所有者)汇款。我知道使用 IPN 可以做到这一点,但我需要使用 SOAP。 最佳答案 您有两个主要选择:使用 Ma
这个问题在这里已经有了答案: Confirm PayPal sandbox account email (3 个答案) 关闭 2 年前。
是否可以使用 paypal API 向任何 paypal 帐户(不仅仅是 API 凭据所有者)汇款。我知道使用 IPN 可以做到这一点,但我需要使用 SOAP。 最佳答案 您有两个主要选择:使用 Ma
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8 年前关闭。 Improve this
我一直在尝试 Meteor。我想使用 OAuth 对我网站上的用户进行身份验证,因为我不想自己实现登录功能。 目前我的网站非常简单。计数器,单击按钮计数器就会加一。当用户转到另一台机器并登录其计数时,
在我看来,您可以输入任何随机的用户名/密码组合,并且嵌入式 UI 小部件和后端都会接受它作为有效的 PayPal 帐户。付款和一切都会完成。 有没有办法可以将 Braintree 沙箱设置为仅接受真实
我已经设置并一直在使用 PayPal 使用 IPN/Express Checkout 在我的主网站上接受订单。但是我还有另外 4 个完全独立的网站,我也需要在它们上使用 PayPal 处理订单。购买我
我来这里是为了尝试解决 paypal 中没有人可以帮助我们解决的看似黑洞的问题。 我们有一个企业帐户。 Paypal Express(数码商品)。已验证,解除限制等...我们有 paypal expr
我正在编写一个 Web 应用程序,过去他们使用自己的 PayPal 帐户为外部自雇人员开设的类(class)付款。然而,税收制度已经改变,慈善机构希望他们的客户通过他们的网站预订(就像以前一样),但直
让我解释一下我的网站(ruby on Rails)的当前场景: 1) 我们可以从我的网站创建多个管理员帐户。 2) 每个管理员都有自己的客户,这些客户也有他们的网站访问部分。 3) 每个客户都可以向他
我正在两个 AWS 账户之间迁移。我想从我的 Mac 临时访问两个帐户上的代码提交存储库。 我已经为两个帐户的用户生成了 HTTPS Git 凭据。当我最初访问旧帐户时,它要求我提供存储在 OSX 钥
是否可以将一笔金额从一个关联账户转移到另一个关联账户?两者都在一个 Stripe 帐户下连接。 我知道我可以在两个帐户之间拆分转账,例如 $transfer = \Stripe\Transfer::c
如果一个人有两个 AWS 账户,一个用于开发,一个用于实时(例如)我知道可以使用 terraform 工作区来管理每个环境的状态。 但是,如果我将工作区从“开发”切换到“实时”,有没有办法告诉 ter
在 Meteor 中,我想将数据(和其他 CRUD 函数)插入到 users 表中,该表是在 Meteor 中下载 account-ui 和 account-password 包时生成的。我尝试在 c
有没有办法将 ETH 添加到 Ganache 账户?我知道我通常可以通过重新启动 ganache cli 来刷新帐户,但我使用的是 --db 选项,这意味着帐户是持久的。因此,它们很快就会枯竭。 最佳
我是一名优秀的程序员,十分优秀!