如何从我们的asp.net应用程序发送电子邮件 [英] how to send an e-mail from our asp.net application

查看:130
本文介绍了如何从我们的asp.net应用程序发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在网上发送来自我网站的电子邮件,但在线下可以执行

i使用以下代码



i'm unable to send an e-mail from my website in online,but in offline it can be executed
i use the following code

MailMessage msg = new MailMessage();
       msg.To.Add(new MailAddress(TextBox3.Text.ToString()));
       msg.From = new MailAddress("myid@gmail.com");
       msg.Subject = "welcome hi";
       msg.Body = "name" + TextBox1.Text + "course" + TextBox2.Text;
       msg.IsBodyHtml = true;
       msg.Priority = MailPriority.Normal;
       SmtpClient smtp = new SmtpClient();
       smtp.Host = "smtp.gmail.com";
       smtp.Port = 587;
       smtp.EnableSsl = true;
       smtp.Credentials = new System.Net.NetworkCredential("myid@gmail.com", "psw");
       smtp.Send(msg);
       Response.Write("<script>alert('mail sent')</script>");

推荐答案

这是不可能的!还没有引入可以离线发送电子邮件的技术(除非我们讨论的是将电子邮件存储在发件箱中)。所以,实际的事情发生在你上线的时候,会引发异常。当您使用网络时,可能会发生许多问题。出现网络,身份验证,SSL或其他基于协议或代理的问题。



您的代码看起来很公平,如果您的身份验证不正确,则会出现唯一的问题。该问题会导致您的应用程序向您显示从Google服务器返回的错误消息,告知您无法使用您提供的凭据发送电子邮件。



此外,由于您没有显示错误消息,我认为唯一的问题是用户名/密码您的帐户是一个非常新的,谷歌现在不允许SMTP设置。 您需要在设置面板中检查,然后允许SMTP或其他设置;我2个月前用我的新帐户遇到了类似的问题。



此外,您使用的代码甚至不是ASP.NET框架,也就是原生.NET框架的 System.Net.Mail 正在使用的命名空间。为此,请阅读我的这篇关于发送电子邮件的文章。 .NET框架和一般问题 - 使用C#代码 [ ^ ]。本文将讨论发送电子邮件时可能出现的问题,以及解决这些问题的解决方案。
That is impossible! No such technology has yet been introduced that can send emails offline (unless we are talking about storing the email in outbox). So, the actual thing happens when you are online, exception is raised. There are a lot of problems that can happen when you are working with networks. Network, authentication, SSL or other protocol or proxy based problems occur.

Your code looks fair to be executed, the only problem occurs if your authentication is not OK. The problem would cause your application to show you an error message that is returned from the Google servers telling you that you cannot send the email, using the credentials that you have provided them with.

Also, since you have not shown the error message, I would assume that the only problem is the username/password or your account is a very new one and Google doesn't allow SMTP settings right now. You need to check that in your settings panel and then allow SMTP or other settings; I had the similar problem 2 months ago with my new account.

Also, the code that you are using is not even of ASP.NET framework, that is native .NET framework's System.Net.Mail namespace being used. For that, please read this article of mine about Sending emails over .NET framework, and general problems – using C# code[^]. The article would discuss the possible problems while sending the emails, and a solution to solve them.


这篇关于如何从我们的asp.net应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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