• 0

C# smtp email


Question

I'm desperately looking for a way to send an email to someone. Everything I try fails. I tried microsofts net.mail namespace. It's not working.

SmtpClient client = new SmtpClient("matt@sndpaintball.com", 26);
			// Specify the e-mail sender.
			// Create a mailing address that includes a UTF8 character
			// in the display name.
			MailAddress from = new MailAddress("jane@contoso.com",
			   "Jane " + (char)0xD8 + " Clayton",
			System.Text.Encoding.UTF8);
			// Set destinations for the e-mail message.
			MailAddress to = new MailAddress("ben@contoso.com");
			// Specify the message content.
			MailMessage message = new MailMessage(from, to);
			message.Body = "This is a test e-mail message sent by an application. ";
			// Include some non-ASCII characters in body and subject.
			string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
			message.Body += Environment.NewLine + someArrows;
			message.BodyEncoding = System.Text.Encoding.UTF8;
			message.Subject = "test message 1" + someArrows;
			message.SubjectEncoding = System.Text.Encoding.UTF8;
			// The userState can be any object that allows your callback 
			// method to identify this send operation.
			// For this example, the userToken is a string constant.
			string userState = "test message1";
			client.SendAsync(message, userState);


			// If the user canceled the send, and mail hasn't been sent yet,
			// then cancel the pending operation
			// Clean up.
			message.Dispose();

It keeps failing. Is there a better way to do this or another library that works better?

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

What's the error you're getting? It looks to me like you're not setting the to and from addresses on the MailMessage object you've created.

Link to comment
Share on other sites

  • 0

MailMessage message = new MailMessage();

message.From = new MailAddress("matt@sndpaintball.com");

message.To.Add(new MailAddress("sathenzar@woh.rr.com"));

message.Subject = "This is my subject";

message.Body = "This is the content";

SmtpClient client = new SmtpClient();

client.Credentials = new NetworkCredential("matt@sndpaintball.com", "mballard");

client.Send(message);

I set my own email addresses, I just didn't post the credentials part. It's odd it says something like it couldn't find the host.

Link to comment
Share on other sites

  • 0

<system.net>

<mailSettings>

<smtp from="test@foo.com">

<network host="matt@sndpaintball.com" port="25" userName="matt@sndpaintball.com" password="mballard" defaultCredentials="true" />

</smtp>

</mailSettings>

</system.net>

Yeah I have it filled out, still fails :(

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.