[英]How to send email through SMTP protocol using CSharp and proxy network?
I am working in a project , In which i will be retrieving the password of the user from the database and mail it to the user email id. 我正在一个项目中工作,在该项目中,我将从数据库中检索用户的密码并将其发送给用户的电子邮件ID。 For this i am using SMTP protocol.
为此,我正在使用SMTP协议。 But i was not able to send the mail from my application.
但是我无法从我的应用程序发送邮件。 I am using proxy network in the company in which i am working.
我在我正在工作的公司中使用代理网络。 I think using proxy network is the reason for getting error while sending the email.
我认为使用代理网络是发送电子邮件时出错的原因。 Is there any alternate solution for sending the email through SMTP protocol from a proxy network.
是否有其他替代解决方案,用于从代理网络通过SMTP协议发送电子邮件。
code used. 使用的代码。
MailMessage mm = new MailMessage("sender@gmail.com", txtEmail.Text.Trim());
mm.Subject = "Password Recovery";
mm.Body = string.Format("Hi {0},<br /><br />Your password is {1}.<br /><br />Thank You.", username, password);
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = "sender@gmail.com";
NetworkCred.Password = "senderpassword";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
lblMessage.ForeColor = Color.Green;
lblMessage.Text = "Password has been sent to your email address.";
Exception image: 异常图片:
您可以设置WebRequest
WebRequest.DefaultWebProxy = new WebProxy("127.0.0.1",8580);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.