开发者

c# Sending emails with authentication. standard approach not working

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

MailMessage me开发者_如何学JAVAssage = new MailMessage();

message.Sender = new MailAddress("sen@der.com");
message.To.Add("reci@pient.com");
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 = "sen@der.com";
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


try this...

NetworkCredential cred = new NetworkCredential(); 

cred.UserName = "sen@der.com"; 
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.


there is no mailbox called sen@der.com on server mail.myhost.com, check that

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜