-2
我想发送自动电子邮件时,有一些机构在我的网站上注册。每当我在网站(本地服务器)上注册时,都没有例外。我还添加了使用system.Net.Mail和web.Config脚本a。 以下是我的一段ASP.NET代码:无法发送电子邮件与c#
public void SendWelcomeMail()
{
string EmailTO = TextBoxEmail.Text;
string EmailFrom = "[email protected]";
string Pass = TextBoxPassword.Text;
try
{
MailMessage message = new MailMessage();
message.From = new MailAddress(EmailFrom);
message.To.Add(new MailAddress(EmailTO));
message.Subject = "Welcome";
message.Body = "You are now registered with your email ID "+EmailTO;
message.Body = "Your Password is "+Pass;
SmtpClient client = new SmtpClient();
client.Send(message);
}
catch
{
Response.Write("Sorry there is an exception. Some thing must be wrong");
}
}
既然你没有指定参数为SmtpClient()构造函数,它正在寻找主机,端口和凭证在应用程序设置或系统配置文件中。你记得配置其中之一吗? – 2015-03-13 18:13:31
不,我只是完全忘了设置主机,在SmtpClient构造函数中添加要添加的其他内容。我明白为什么我无法发送电子邮件。谢谢。 – 2015-03-13 18:28:19