邮件发送失败 [英] Failure sending mail
本文介绍了邮件发送失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试
{
如果 (Upload_image.HasFile&& Upload_sign.HasFile&& Captcha1.UserValidated)
{
int i = cmd.ExecuteNonQuery() ;
if (i > 0 )
{
// 成功提交表格后,将注册号码发送到用户的邮箱
SmtpClient smtpc = new SmtpClient( smtp.gmail.com跨度>);
smtpc.Port = 587 ;
smtpc.EnableSsl = true ;
smtpc.UseDefaultCredentials = false ;
string user = ajay.mukesh @ gmail.com跨度>; // < - 在此处输入您的Gmail代码
string pass = password; // < - 在此输入您的Gmail密码
string sub = 表格填写申请表:; // 您网站的主题
string msg = Webcome to http://msdotnet.co.in您的注册号是: + Label2.Text; // 邮件正文
smtpc.Credentials = 新的 NetworkCredential(用户,通行证);
MailMessage email = new MailMessage(user,TextBox6.Text,sub,msg);
email.IsBodyHtml = true ;
smtpc.Send(电子邮件);
Label1.Text = 您的表单已成功提交。立即预览,注册数字是:;
Label3.Text = null ;
}
else
{
Label1.Text = 您的表单未成功提交请稍后再试;
Label3.Text = null ;
Label2.Text = null ;
}
}
else
{
Label3.ForeColor = System.Drawing.Color.Red;
Label3.Text = 输入有效的验证码;
Label2.Text = null ;
}
}
catch (例外情况)
{
Label1.Text = ex.Message;
}
最后
{
con.Close();
}
解决方案
var client = new SmtpClient( smtp.gmail。 com, 587 )
{
Credentials = new NetworkCredential ( ajay.mukesh@gmail.com, 密码),
EnableSsl = true
};
client.Send( new MailMessage(user,recepients,sub,msg)
{IsBodyHtml = 真的};
这段代码一直对我有用......
尝试创建一个简单的控制台项目...
我的猜测是你需要检查对TO字段的引用...
如果您要发送一封电子邮件,您只需传递一个字符串......但是当您需要发送倍数时,文档似乎建议, 应该用来分隔收件人......
message.To.Add( 一个@ example.com,两个@ example.com));
或者
client.Send( new MailMessage(user, 一个@ example.com,两个@ example.com,sub,msg)
{IsBodyHtml = true };
如果没有空格,它永远不会看起来整洁...
try
{
if (Upload_image.HasFile && Upload_sign.HasFile && Captcha1.UserValidated)
{
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
// Send Regisration number to user's mail box after submitting the form successfully
SmtpClient smtpc = new SmtpClient("smtp.gmail.com");
smtpc.Port =587;
smtpc.EnableSsl = true;
smtpc.UseDefaultCredentials = false;
string user = "ajay.mukesh@gmail.com"; //<--Enter your gmail id here
string pass = "password";//<--Enter Your gmail password here
string sub = "Form filling Application:"; //Subject for your website
string msg = "Webcome to http://msdotnet.co.in Your Registration Number is: " + Label2.Text; //Message body
smtpc.Credentials = new NetworkCredential(user, pass);
MailMessage email = new MailMessage(user, TextBox6.Text, sub, msg);
email.IsBodyHtml = true;
smtpc.Send(email);
Label1.Text = "Your form has been submitted successfully.Take Preview Now,Your Registration Number is: ";
Label3.Text = null;
}
else
{
Label1.Text = "Your form has been not submitted successfully try again later";
Label3.Text = null;
Label2.Text = null;
}
}
else
{
Label3.ForeColor = System.Drawing.Color.Red;
Label3.Text = "Enter Valid Captcha code";
Label2.Text = null;
}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
finally
{
con.Close();
}
解决方案
var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("ajay.mukesh@gmail.com", "password"), EnableSsl = true }; client.Send(new MailMessage(user, recepients, sub, msg) { IsBodyHtml = true};
This snippet has always worked for me...
Try creating a simple console project...
My guess is that you need to check the reference to the "TO" field...
If you are sending a single email, you can just pass a string... But when you need to send multiples, the documentation seems to suggest that a "," should be used to separate the receipents...
message.To.Add("one@example.com,two@example.com"));
or
client.Send(new MailMessage(user, "one@example.com,two@example.com", sub, msg) { IsBodyHtml = true};
it never looks neat without the spaces...
这篇关于邮件发送失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文