我正在通过 gmail 帐户发送电子邮件。但是当我运行程序时,发生 smtp 异常。当我
打开详细信息时。它显示内部异常 - “{”无法从传输连接读取数据:现有连接被远程主机强行关闭。 “}”
**.aspx code:**
your Email assdress:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Labe3"></asp:Label>
<asp:button ID="Button1" runat="server" text="Button" OnClick="button1_click" />
**.aspx.cs**
public void button1_click(object sender, EventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(TextBox1.Text);
// You can specify the host name or ipaddress of your server
// Default in IIS will be localhost
smtpClient.Host = "smtp.gmail.com";
smtpClient.EnableSsl = true;
//Default port will be 25
smtpClient.Port = 25;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.To.Add("irfan.dilwaley@gmail.com");
message.Subject = "Feedback";
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("admin1@yoursite.com")
// You can specify Address directly as string
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = false;
// Message body content
// Send SMTP mail
smtpClient.Send(message);
Label3.Text = "Email successfully sent.";
}
}