Sending Email

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);
}
}
}
}
 
C

Chris Shepherd

Joe said:
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?
[...]

My bet is that postoffice.worldnet.att.net is probably not permitted to
send or receive emails for your from or to domains.

You can telnet in yourself and try it:
http://www.yuki-onna.co.uk/email/smtp.html


Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top