C#发送电子邮件的问题 [英] C# issue with sending email

查看:114
本文介绍了C#发送电子邮件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我正在为我的应用程序创建一个忘记密码屏幕,供用户重置密码。然后,该程序应该将具有更新密码的电子邮件发送到与用户名相关联的电子邮件帐户。当前状态是程序在到达smtp.send(message)命令时冻结并最终超时。我在我的工作中尝试了gmail服务器信息和我的smtp服务器。根本没有发送电子邮件。有谁知道这与代码或电子邮件设置有关吗?



谢谢大家!



Hi everyone!

I am creating a forgot password screen for my application for users to reset their passwords. The program is then supposed to send emails with the updated password to the email account associated with the username. The current status is is that the program freezes when it reaches the smtp.send(message) command and eventually times out. I''ve tried this with the gmail server information and my smtp server here at my work. No email is being sent at all. Does anyone know if this has to do with the code or with an email setting?

Thanks everyone!

MailMessage message = new MailMessage();
message.To.Add(userEmail);
message.From = new MailAddress("***@gmail.com");
message.Subject = "New test mail";
message.Body = "Hello test message succeed";
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.ASCII;
message.Priority = System.Net.Mail.MailPriority.High;
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new NetworkCredential("username", "password");

try
{
     smtp.Send(message);
}
catch (Exception ex)
{
     throw ex;
}

推荐答案

代码LOOKS正确,但不知道抛出的异常,很难说。



网络凭证必须是有效的GMail登录名。



你的工作服务器不能lbokc访问GMail服务器(大多数公司网络都可以!)



如果您要使用公司,则无法在发件人字段中使用您的GMail电子邮件地址SMTP服务器。您必须使用在公司电子邮件系统中有效的地址,这是非常好的。
The code LOOKS correct, but without knowing the exception that''s thrown, it''s difficult to say.

The network credentials must be a valid GMail login name.

Your work server cannot lbokc access to the GMail servers (most corporate networks do!)

You cannot use your GMail email address in the From field if you''re going to use your corporate SMTP server. Chances are really good that you must use an address that is valid in your corporate email system.


这篇关于C#发送电子邮件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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