本文介绍了发送邮件时出现问题。没有错误,但邮件没有发送....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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("[email protected]");
                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("[email protected]", "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);
            }
        }

推荐答案

If this resolves your issue; please mark the question as answered & Acknowledge the same.

Regards,
Subhash Konduru



这篇关于发送邮件时出现问题。没有错误,但邮件没有发送....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:15