Reputation: 2142
In .NET, can I send email using the identity of an AD group that I own?
My current code:
using (var smtp = new SmtpClient("smtp.somecompany.com"))
{
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
var mail = new MailMessage("[email protected]", recipients)
{
...
};
smtp.Send(mail);
}
And I'm getting
System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender
I know I can send as a different user by using
smtp.Credentials = new NetworkCredential(...)
and pass name/password pair.
However, an AD group does not have a password, and I don't think the group alias even count as a user name.
So is it possible to send email as the group at all?
Upvotes: 5
Views: 7563
Reputation: 432
If you are able send email with single user email-ID internally (your organization users) but not with group email-ID, check whether you are using correct SMTP address for the group email-ID (check properties for this email in outlook).
As mentioned in the previous answer AD groups not directly related to email. You can create Contacts (email-ID but no mail box) and Users (email-ID with mail box).
In java I am using:
String SMTP_HOST_NAME = "exchange_server";
String SMTP_AUTH_USER = "[email protected]";
String SMTP_AUTH_PWD = "";
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "false");
NOTE: Please check SMTP_AUTH_PWD is blank and also mail.smtp.auth is false.
Also, check for mail relay option specially for mails to external domains:
Mail relay option: Contact your MS-exchange team to enable this option for your server.
Help Link: https://confluence.atlassian.com/display/CONFKB/550+5.7.1+Unable+to+Relay+Mail+From+Exchange+Server
After enabling this option may be all users cannot send email to external domains, it depends on your company policy. So, after successful mail sent from your application to MS-Exchange it can be blocked at Email Security Appliances (like cisco ironport). Hope this will help.
Upvotes: 1
Reputation: 2610
In .NET, can I send email using the identity of an AD group that I own?
Well sort of. You have to create / pick a user(s) in AD then assign that user(s) to a mail enabled universal security group. Make sure to assign an email address to the group. Then in .net code you will have to authenticate as one of the users but change the mail.from to the mail enabled universal security group email address. Now if anyone replies to the email the message will go to the mail enabled universal security group with will in turn forward to all users inside the group. Exchange requires authentication so you can pick anyone in the mail enabled security group as the authenticator.
http://technet.microsoft.com/en-us/library/bb123805(v=exchg.141).aspx
Upvotes: 0
Reputation: 1106
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("[email protected]");
// The important part -- configuring the SMTP client
SmtpClient smtp = new SmtpClient();
smtp.Port = 587; // [1] You can try with 465 also, I always used 587 and got success
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential(mail.From, "password_here"); // [4] Added this. Note, first parameter is NOT string.
smtp.Host = "smtp.somecompany.com";
//recipient address
mail.To.Add(new MailAddress("[email protected]"));
//Formatted mail body
mail.IsBodyHtml = true;
mail.Body = st;
smtp.Send(mail);
Please Try It, And give your port number whose issue you
How to send email in ASP.NET C#
After all check this link..
Upvotes: -1
Reputation: 4101
AD groups are security objects, and not directly related to email. If for example you had a development group and you wanted anyone in the dev group to access the mailbox, with exchange it's possible to set up a shared mailbox that anyone in the AD group can access. It is also possible to set the outgoing address for that mailbox to be [email protected].
When you have created the shared mailbox using the code in your example would work correctly.
Upvotes: 1