J
Joe Cool
I am using the following code to try and send an email message through
my ISP. I get an exception "An existing connection was forcibly closed
by the remote host". Any ideas why?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
namespace SendMail
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cmdSendMail_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
SmtpClient smtp = new SmtpClient();
try
{
msg.From = new MailAddress("(e-mail address removed)");
msg.To.Add("(e-mail address removed)");
msg.Subject = "this is the subject of the message";
msg.Body = "this is the body of the message";
smtp.Host = "postoffice.worldnet.att.net";
smtp.Port = 25;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new
NetworkCredential("(e-mail address removed)", "mypassword");
smtp.Send(msg);
MessageBox.Show("Sent");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
my ISP. I get an exception "An existing connection was forcibly closed
by the remote host". Any ideas why?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
namespace SendMail
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cmdSendMail_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
SmtpClient smtp = new SmtpClient();
try
{
msg.From = new MailAddress("(e-mail address removed)");
msg.To.Add("(e-mail address removed)");
msg.Subject = "this is the subject of the message";
msg.Body = "this is the body of the message";
smtp.Host = "postoffice.worldnet.att.net";
smtp.Port = 25;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new
NetworkCredential("(e-mail address removed)", "mypassword");
smtp.Send(msg);
MessageBox.Show("Sent");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}