邮件功能不起作用? [英] Mail Function Not Working?
本文介绍了邮件功能不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里写邮件功能。我想发送测试邮件。但它会显示异常远程服务器未连接。
我的代码在这里:
public void sendEmailComp()
{
if (ViewState [ LM_Email] == null )
{
ScriptManager.RegisterStartupScript( this , this .GetType(),< span class =code-string> AlertCode, alert('发送邮件时出错'\\
nLine Manager的电子邮件未找到..'), true );
}
else
{
if (ViewState [ App_Email] == null )
{
ScriptManager.RegisterStartupScript( this , this .GetType(), AlertCode, alert('发送邮件时出错'\\\ nn'Applicant未找到'), true );
}
else
{
string ToEmailId = ViewState [ App_Email]。ToString();
string FromMail = ViewState [ LM_Email 跨度>]的ToString();
string CopyMail = webelink @ elinktechnologies。净跨度>;
尝试
{
System.Net.Mail.MailMessage mess = new System.Net.Mail.MailMessage();
mess.Subject = 您的请假申请已处理;
mess.IsBodyHtml = true ;
mess.Body = < table style = width:100%; FONT-FAMILY:宋体;颜色:黑色;大小:10px的; text-align:left > +
< tr>< td style = font-weight:bold > +
亲爱的 + ViewState [ App_Name]。ToString()+ ,< br />< br /> +
< / td>< / tr> +
< tr>< td> +
您的请假申请已被处理:< br />< br />< br /> +
< / td>< / tr> +
< tr>< td> +
< table border = 1 > +
< tr> +
< td>离开状态< / td> +
< td> + ViewState [< span class =code-string> LeaveStatus]。ToString()+ < / td> +
< / tr> +
< tr> +
< td>保留类型< / td> +
< td> + ViewState [ LeaveTypeName]。ToString()+ < / td> +
< / tr> +
< tr> +
< td> WorkOn Date< / td> ; +
< td> + ViewState [ WorkOnDate]。ToString()+ < / td> +
< / tr> +
< tr> +
< td>比较日期< / td> +
< td> ; + ViewState [ CompDate]。ToString()+ < / td> +
< / tr> +
< tr> +
< span class =code-string>< td>评论/原因< / td> +
< td> + ViewState [ 评论] .ToString()+ < / td> +
< / tr> +
< / table> +
< br />< br />< br /> +
< / td> +
< / tr> +
< ; tr> +
< td> +
问候, +
< / td>< / tr> +
< span class =code-string>< tr> +
< td style = font-weight:bold > +
+ ViewState [ LM_Name]。ToString()+ +
< / td>< / tr> +
< / table>跨度>;
mess.To.Add(ToEmailId);
mess.From = new MailAddress(FromMail);
mess.CC.Add(CopyMail);
SmtpClient sc = new SmtpClient();
sc.Host = 103.242.119.215;
sc.Send(mess);
ViewState [ Email_Sent] = Y;
ViewState [ Email_Reason] = ;
}
catch (Exception exe)
{
ViewState [ Email_Sent] = N< /跨度>;
ViewState [ Email_Reason] = exe.Message;
}
}
}
}
解决方案
< blockquote>查看这些解决方案..
http://stackoverflow.com/questions/23360415/fail-sending-email-unable-to-connect-the-remote-server [ ^ ]
http://stackoverflow.com/questions/18060559/unable- to-connect-to-remote-server-c-sharp-while-sending-mail [ ^ ]
http://stackoverflow.com/questions/24931227/cannot-send-mail-from-remote-server-system-net-mail -smtpexception-failure-sendi [ ^ ]
I Written mail function here. I want to send test mail. But it will shows exception Remote server is not connected.
My Code is here:
public void sendEmailComp()
{
if (ViewState["LM_Email"] == null)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "AlertCode", "alert('Error in sending mail\\nLine Manager's Email Not Found..')", true);
}
else
{
if (ViewState["App_Email"] == null)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "AlertCode", "alert('Error in sending mail\\nApplicant's Not Found')", true);
}
else
{
string ToEmailId = ViewState["App_Email"].ToString();
string FromMail = ViewState["LM_Email"].ToString();
string CopyMail = "webelink@elinktechnologies.net";
try
{
System.Net.Mail.MailMessage mess = new System.Net.Mail.MailMessage();
mess.Subject = "Your Leave Application Processed";
mess.IsBodyHtml = true;
mess.Body = "<table style="width:100%; font-family:Arial; color:Black; size:10px; text-align:left">" +
"<tr><td style="font-weight:bold">" +
"Dear " + ViewState["App_Name"].ToString() + ",<br /><br />" +
"</td></tr>" +
"<tr><td>" +
"Your Leave Application Has Been Processed :<br /><br /><br />" +
"</td></tr>" +
"<tr><td>" +
"<table border="1">" +
"<tr>" +
"<td>Leave Status</td>" +
"<td>" + ViewState["LeaveStatus"].ToString() + "</td>" +
"</tr>" +
"<tr>" +
"<td>Leave Type</td>" +
"<td>" + ViewState["LeaveTypeName"].ToString() + "</td>" +
"</tr>" +
"<tr>" +
"<td>WorkOn Date</td>" +
"<td>" + ViewState["WorkOnDate"].ToString() + "</td>" +
"</tr>" +
"<tr>" +
"<td>Comp Date</td>" +
"<td>" + ViewState["CompDate"].ToString() + "</td>" +
"</tr>" +
"<tr>" +
"<td>Comment/Reason </td>" +
"<td>" + ViewState["Comment"].ToString() + "</td>" +
"</tr>" +
"</table>" +
"<br /><br /><br />" +
"</td>" +
"</tr>" +
"<tr>" +
"<td>" +
"Regards," +
"</td></tr>" +
"<tr>" +
"<td style="font-weight:bold">" +
"" + ViewState["LM_Name"].ToString() + "" +
"</td></tr>" +
"</table>";
mess.To.Add(ToEmailId);
mess.From = new MailAddress(FromMail);
mess.CC.Add(CopyMail);
SmtpClient sc = new SmtpClient();
sc.Host = "103.242.119.215";
sc.Send(mess);
ViewState["Email_Sent"] = "Y";
ViewState["Email_Reason"] = "";
}
catch (Exception exe)
{
ViewState["Email_Sent"] = "N";
ViewState["Email_Reason"] = exe.Message;
}
}
}
}
解决方案
see these solution..
http://stackoverflow.com/questions/23360415/fail-sending-email-unable-to-connect-the-remote-server[^]
http://stackoverflow.com/questions/18060559/unable-to-connect-to-remote-server-c-sharp-while-sending-mail[^]
http://stackoverflow.com/questions/24931227/cannot-send-mail-from-remote-server-system-net-mail-smtpexception-failure-sendi[^]
这篇关于邮件功能不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文