views:

40

answers:

1

Hi All,

I have recently purchased a new computer, and now my e-mails never get sent, and there are NEVER any exceptions thrown or anything.

Can somebody please provide some samples that work using the SmtpClient class? Any help at all will be greatly appreciated.

Thank you

Updates


Ok - I have added credentials now. And can SUCCESSFULLY SEND e-mail synchronously. But I can still not send them asynchronously.

Old: After trying to send e-mail synchronously, I receive the following exception:

Transaction failed. The server response was:

5.7.1 <[email protected]>: Relay access denied.

+1  A: 

You could first try the synchronous Send method to verify that everything is setup correctly with the SMTP server and that you don't get any exceptions:

var client = new SmtpClient("smtp.somehost.com");
var message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "test";
message.Body = "test body";
client.Send(message);

Remark: In .NET 4 SmtpClient implements IDisposable so make sure you wrap it in a using statement.

Darin Dimitrov
Thank you very much; I am trying this now. I have already tried that but my code was abit different, so I'll try it your way.
lucifer
Okay, I got an exception: Transaction failed. The server response was: 5.7.1 <[email protected]>: Relay access denied - I will update my question with progress. I have no idea what this means
lucifer
It means that the SMTP server you are using is not configured to relay mails to upstream servers. If you are using IIS you may take a look at this article: http://support.microsoft.com/kb/293800
Darin Dimitrov
I'm using the same e-mail service (BlueBottle) to send e-mails. I've been doing this for years. I've also tried several other email accounts to send e-mail. Same story.
lucifer
Well then you might have more luck asking your question on http://serverfault.com/ as this is no longer programming related.
Darin Dimitrov
After implementing your code I forgot to add credentials. I added credentials to "client", and now I CAN send email Synchronously. But still cannot send mail Asynchronously.
lucifer
This IS a programming related question.
lucifer