发送邮件时出现问题。没有错误,但邮件没有发送.... [英] Problem on sending mail.It gives no error but mail isn't sending....
本文介绍了发送邮件时出现问题。没有错误,但邮件没有发送....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
test.aspx
test.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.Button
{
background-color :#FF5A00;
color: #FFFFFF;
font-weight: bold;
margin-right: 2px;
padding: 4px 20px 4px 21px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellspacing="2" cellpadding="2" border="0">
<tr><td></td><td>Contact Us Form</td></tr>
<tr><td>Name</td><td><asp:TextBox ID="txtName" runat="server" /></td></tr>
<tr><td>Email</td><td><asp:TextBox ID="txtEmail" runat="server" /></td></tr>
<tr><td>Subject</td><td><asp:TextBox ID="txtSubject" runat="server" /></td></tr>
<tr><td valign="top">Message</td><td> <asp:TextBox ID="txtMessage" Rows="5" Columns="40" TextMode="MultiLine" runat="server"/></td></tr>
<tr><td></td><td><asp:button ID="btnSubmit" Text="Submit" runat="server" onclick="btnSubmit_Click" CssClass="Button"/></td></tr>
<tr><td colspan="2" style=" color:red"><asp:Label ID="lbltxt" runat="server"/></td></tr>
</table>
</div>
</form>
</body>
</html>
test.aspx.cs
test.aspx.cs
using System;
using System.Net.Mail;
private void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtEmail.Text);
// Recipient e-mail address.
Msg.To.Add("youremail@gmail.com");
Msg.Subject = txtSubject.Text;
Msg.Body = txtMessage.Text;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("youremail@gmail.com", "yourpassword");
smtp.EnableSsl = true;
smtp.Send(Msg);
//Msg = null;
lbltxt.Text = "Thanks for Contact us";
// Clear the textbox valuess
txtName.Text = "";
txtSubject.Text = "";
txtMessage.Text = "";
txtEmail.Text = "";
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
推荐答案
这可能是Gmail用户验证过程中的问题。我建议您可以尝试使用您传入的凭据集手动登录Gmailnew System.Net.NetworkCredential(youremail@gmail.com,yourpassword);。
如果您在登录时看到任何恢复页面;你应该采取适当的行动,以便你可以通过Gmail SMTP服务发送电子邮件。
Hi,
It could be a problem with the User validation process from Gmail. I would suggest you can try logging in the Gmail manually with the credential set you are passing in "new System.Net.NetworkCredential("youremail@gmail.com", "yourpassword");".
If you see any recovery page upon login; you should Take proper action such that you can send Email through Gmail SMTP service.
If this resolves your issue; please mark the question as answered & Acknowledge the same.
Regards,
Subhash Konduru
删除Try-Catch并查看错误。
Hi,
Remove Try -Catch & See the error.
这篇关于发送邮件时出现问题。没有错误,但邮件没有发送....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文