<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Damir's Corner - Software|Exchange</title>
    <link>http://www.damirscorner.com/</link>
    <description>Notes from Daily Encounters with Technology</description>
    <language>en-us</language>
    <copyright>Damir Arh, M. Sc.</copyright>
    <lastBuildDate>Sun, 09 Aug 2009 17:39:38 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>damir.arh@gmail.com</managingEditor>
    <webMaster>damir.arh@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=21209566-9f7f-4939-ace5-d224080bb8b1</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,21209566-9f7f-4939-ace5-d224080bb8b1.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,21209566-9f7f-4939-ace5-d224080bb8b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=21209566-9f7f-4939-ace5-d224080bb8b1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft Exchange supports Send As and Send On Behalf Of permissions to be granted
to users for individual e-mail addresses. Sending e-mail from Outlook for these users
is very simple – they just enter the desired address in the From field of a new message
(toggled with the Show From command on the Options ribbon) and if they have the required
permission it will be sent accordingly – either as if it was actually sent from that
address or as sent by the user on behalf of the address in the From field.
</p>
        <p>
If you want to achieve this from code there is a little more work involved. First
of all the user must be authenticated on the server using one of the methods below:
</p>
        <p>
          <font face="Courier New">SmtpClient smtp = new SmtpClient("smtp.domain.com");</font>
        </p>
        <p>
          <font face="Courier New">// use user’s existing credentials<br />
smtp.UseDefaultCredentials = true;</font>
        </p>
        <p>
          <font face="Courier New">// pass username and password<br />
smtp.Credentials = new NetworkCredentials("username", "password");</font>
        </p>
        <p>
The next step is to set up the correct headers in the message otherwise the server
will return error code 5.7.1 describing the permission the user does not have.
</p>
        <p>
To send the e-mail as only the From property has to contain the desired address:
</p>
        <p>
          <font face="Courier New">MailMessage mail = new MailMessage();<br />
mail.From = new MailAddress("send.as@domain.com");</font>
        </p>
        <p>
To send the e-mail on behalf of another user the Sender property must additionally
contain the user’s e-mail address:
</p>
        <p>
          <font face="Courier New">MailMessage mail = new MailMessage();<br />
mail.From = new MailAddress("send.as@domain.com");<br />
mail.Sender = new MailAddress("user.address@domain.com");</font>
        </p>
        <p>
On a related note, the required permissions can be granted using PowerShell.
</p>
        <p>
To grant the Send As permission:
</p>
        <p>
          <font face="Courier New">Add-ADPermission –Identity "user1" –User "user2" –ExtendedRights
Send-As</font>
        </p>
        <p>
To grant the Send On Behalf Of permission:
</p>
        <p>
          <font face="Courier New">Set-Mailbox "user1" -GrantSendOnBehalfTo "user2"</font>
        </p>
        <p>
In both cases the user1 specifies the mailbox to grant the permission for and the
user2 specifies the user to grant the permission to.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=21209566-9f7f-4939-ace5-d224080bb8b1" />
      </body>
      <title>Send E-Mail As and On Behalf Of</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,21209566-9f7f-4939-ace5-d224080bb8b1.aspx</guid>
      <link>http://www.damirscorner.com/SendEMailAsAndOnBehalfOf.aspx</link>
      <pubDate>Sun, 09 Aug 2009 17:39:38 GMT</pubDate>
      <description>&lt;p&gt;
Microsoft Exchange supports Send As and Send On Behalf Of permissions to be granted
to users for individual e-mail addresses. Sending e-mail from Outlook for these users
is very simple – they just enter the desired address in the From field of a new message
(toggled with the Show From command on the Options ribbon) and if they have the required
permission it will be sent accordingly – either as if it was actually sent from that
address or as sent by the user on behalf of the address in the From field.
&lt;/p&gt;
&lt;p&gt;
If you want to achieve this from code there is a little more work involved. First
of all the user must be authenticated on the server using one of the methods below:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;SmtpClient smtp = new SmtpClient("smtp.domain.com");&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;// use user’s existing credentials&lt;br&gt;
smtp.UseDefaultCredentials = true;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;// pass username and password&lt;br&gt;
smtp.Credentials = new NetworkCredentials("username", "password");&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The next step is to set up the correct headers in the message otherwise the server
will return error code 5.7.1 describing the permission the user does not have.
&lt;/p&gt;
&lt;p&gt;
To send the e-mail as only the From property has to contain the desired address:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;MailMessage mail = new MailMessage();&lt;br&gt;
mail.From = new MailAddress("send.as@domain.com");&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
To send the e-mail on behalf of another user the Sender property must additionally
contain the user’s e-mail address:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;MailMessage mail = new MailMessage();&lt;br&gt;
mail.From = new MailAddress("send.as@domain.com");&lt;br&gt;
mail.Sender = new MailAddress("user.address@domain.com");&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
On a related note, the required permissions can be granted using PowerShell.
&lt;/p&gt;
&lt;p&gt;
To grant the Send As permission:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;Add-ADPermission –Identity "user1" –User "user2" –ExtendedRights
Send-As&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
To grant the Send On Behalf Of permission:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;Set-Mailbox "user1" -GrantSendOnBehalfTo "user2"&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
In both cases the user1 specifies the mailbox to grant the permission for and the
user2 specifies the user to grant the permission to.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=21209566-9f7f-4939-ace5-d224080bb8b1" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,21209566-9f7f-4939-ace5-d224080bb8b1.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Software</category>
      <category>Software/Exchange</category>
    </item>
  </channel>
</rss>