I have a .NET program -- a Windows Service -- that connects to Exchange to send email. The goal is to allow it to send email appearing to be from any number email addresses within the domains my employer owns. The program is authenticating with an Active Directory account -- called "AutoMail" -- and the problem is that Exchange is giving the following error response code:
System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at ConsoleApplication1.Program.Main(String args) in C:\WorkingCode\ConsoleApplication1\ConsoleApplication1\Program.cs:line 38
When I change the network credentials to my A/D login and send email as being from me, it works with no problem.
So my question is: can the AutoMail user be configured from the Exchange side to be allowed to send email as any validly formatted email address? If so, how?
For reference, here's the C# code in use:
MailMessage mail = new MailMessage(); mail.From = new MailAddress("firstname.lastname@example.org"); mail.To.Add("email@example.com"); mail.Subject = "This is an email"; mail.Body = "This is a test. <b>This is bold</b> <font color=#336699>This is blue</font>"; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "172.16.1.33"; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential("AutoMail", "password"); smtp.Send(mail);