Reputation: 908
I'm using smtp (c#)and trying to send mail to group id(official id) but its not able to send mail.Although through same code I'm able to send mail to individual id. Any idea what could be wrong here. Following code I'm using
MailMessage mail = new MailMessage();
mail.To = "[email protected]";
mail.From = "[email protected]";
mail.Subject = "Test Mail: please Ignore";
mail.Body = body;
SmtpMail.SmtpServer = "mailhub.int.company.com";
SmtpMail.Send(mail)
I'm getting following error in my mail box:
Delivery has failed to these recipients or distribution lists:
[email protected]
Not Authorized. You are not authorized to send to this recipient or distribution list. For distribution lists please check approved senders in the corporate directory.
_____
Sent by Microsoft Exchange Server 2007
Diagnostic information for administrators:
Generating server: GSPWMS005.int.company.com
[email protected]
#550 5.7.1 RESOLVER.RST.AuthRequired; authentication required ##
From error I could get an idea that some authentication is missing but not sure which one or how to resolve it. If I send mail to this group thorough my outlook then its working ok.
Upvotes: 1
Views: 7923
Reputation: 17858
http://msdn.microsoft.com/en-us/library/59x2s2s6.aspx
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test e-mail message sent by an application. ";
message.Subject = "Test Email using Credentials";
NetworkCredential myCreds = new NetworkCredential("username", "password", "domain");
CredentialCache myCredentialCache = new CredentialCache();
try
{
myCredentialCache.Add("ContoscoMail", 35, "Basic", myCreds);
myCredentialCache.Add("ContoscoMail", 45, "NTLM", myCreds);
client.Credentials = myCredentialCache.GetCredential("ContosoMail", 45, "NTLM");
client.Send(message);
Console.WriteLine("Goodbye.");
}
catch(Exception e)
{
Console.WriteLine("Exception is raised. ");
Console.WriteLine("Message: {0} ",e.Message);
}
Upvotes: 1