tags:

views:

119

answers:

2

I am trying to send an email using the following very standard code. However, I get the error that follow...

MailMessage message = new MailMessage();

message.Sender = new MailAddress("[email protected]");
message.To.Add("[email protected]");
message.Subject = "test subject";
message.Body = "test body";

SmtpClient client = new SmtpClient();
client.Host = "mail.myhost.com";
//client.Port = 587;

NetworkCredential cred = new NetworkCredential();

cred.UserName = "[email protected]";
cred.Password = "correct password";
cred.Domain = "mail.myhost.com";
client.Credentials = cred;
client.UseDefaultCredentials = false;     

client.Send(message);

Mailbox unavailable. The server response was: No such user here.

This recipient email address definitely works. To make this account work I had to do some special steps in outlook. Specifically, I had to do change account settings -> more settings -> outgoing server -> my outgoing server requires authentication & use same settings. I am wondering if there is some other strategy.

I think the key here is that my host is Server Intellect and I know that some people on here use them so hopefully someone else has been able to get through this. I did talk to support but they said with coding issues I am on my own :o

A: 

there is no mailbox called [email protected] on server mail.myhost.com, check that

Andrey
how do you know? You can configure every MTA (you own) to accept mails for every domain you like.
Oliver
Whether you can configure your own MTA to accept mail for some other domain doesn't matter. The sending code will still do an MX record lookup to determine which is the real server to send the mail to.
Chris Lively
@Oliver i know it from "The server response was: No such user here"
Andrey
@Andrey: You're right, i skipped that part in the question that he got this error message.
Oliver
+2  A: 

try this...

NetworkCredential cred = new NetworkCredential(); 

cred.UserName = "[email protected]"; 
cred.Password = "correct password"; 
//cred.Domain = "mail.myhost.com"; 

... you should not need to provide the .Domain unless you are using Kerberos or some other complex authentication.

Edit...

Check out my extended answer. It has an example of how to send an email with authentication. It's also has SSL enabled so you may need to remove that part.

Matthew Whited