<

Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x

How to set up an email signature rule in Office 365 based on existing HTML file using PowerShell

Published on
3,765 Points
665 Views
1 Endorsement
Last Modified:
CodeTwo Software
We make practical tools for Microsoft Exchange, Office 365 and Outlook. Visit our website to learn about our paid and freeware products.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office 365 via Windows PowerShell using Exchange Online tr

Preparing the HTML email signature file


Exchange Online transport rule disclaimers accept the following types of content:
  • Text
  • HTML code and inline CSS
  • Images hosted online (inserted using the HTML <img> tag)
  • Dynamic placeholders for users' Azure AD data*
* The placeholders must be provided in this fashion: %%Name of AD attribute%%. For more details, including a list of available attributes, see this article: http://www.mail-signatures.com/articles/active-directory-data-in-email-signatures/?sts=6492

NOTE: The file should be prepared in Text format, e.g. TXT or HTM.

Example of Exchange Online transport rule disclaimer code:
 
<TABLE style="WIDTH: 460px">
  <TBODY>
    <TR>
      <TD style="FONT-SIZE: 10pt; HEIGHT: 25px; FONT-FAMILY: Arial; WIDTH: 222px" align=left>
        <P><STRONG>CodeTwo</STRONG> | Software Engineering<BR></P>
        <P style="FONT-SIZE: 8pt">Wolnosci 16, 58-500 Jelenia Gora<BR>
          Poland (EU)<BR>
          + 48 75 64 61 001<BR>
          + 48 75 64 61 003 (fax)
        </P>
      </TD>
      <TD style="FONT-SIZE: 10pt; HEIGHT: 25px; FONT-FAMILY: Arial; WIDTH: 232px" align=right vAlign=top>
        <A href="https://www.youtube.com/user/CodeTwoChannel"><IMG style="HEIGHT: 25px; WIDTH: 25px" border=0 src="http://www.mail-signatures.com/articles/wp-content/uploads/2014/08/youtube.png"></A>
        <A href="http://www.facebook.com/CodeTwo"><IMG style="HEIGHT: 25px; WIDTH: 25px" border=0 src="http://www.mail-signatures.com/articles/wp-content/uploads/2014/08/facebook.png"></A>
        <A href="https://plus.google.com/+CodeTwoSoftware"><IMG style="HEIGHT: 25px; WIDTH: 25px" border=0 src="http://www.mail-signatures.com/articles/wp-content/uploads/2014/08/googleplus-2.png"></A>
        <A href="https://twitter.com/CodeTwoSoftware"><IMG style="HEIGHT: 25px; WIDTH: 25px" border=0 src="http://www.mail-signatures.com/articles/wp-content/uploads/2014/08/twitter.png"></A>
      </TD>
    </TR>
    <TR>
      <TD style="FONT-SIZE: 10pt; HEIGHT: 25px; FONT-FAMILY: Arial" align="middle" colSpan=2>
        <A href="http://www.codetwo.com/email-signatures/"><IMG border=0 src="http://www.mail-signatures.com/articles/wp-content/uploads/2016/11/esig365-banner.png"></A>
      </TD>
    </TR>
  </TBODY>
</TABLE>

Open in new window


Importing the email signature code into a PowerShell session


Learn how to start a remote PowerShell session to Office 365: http://www.codetwo.com/admins-blog/start-remote-powershell-session-connect-exchange-office-365/?sts=6492

Once the text file containing the email signature code is saved to your local drive, you can import its contents into PowerShell. To do this run the below script:
 
$signature = Get-Content <HTML email signature file path>

Open in new window


Learn more about Get-Content cmdlet: https://technet.microsoft.com/en-us/library/hh849787.aspx
 

Creating the email signature transport rule


This is done using the New-TransportRule cmdlet with the -ApplyHtmlDisclaimerText parameter.

To set up a general email signature policy that would add the HTML code you've just imported to all outgoing and internal emails, you just have to run:
 
New-TransportRule -Name <name of transport rule> -ApplyHtmlDisclaimerText "$signature"

Open in new window


But you can also use a wide range of conditions and exceptions* to limit scopes of senders and/or recipients, trigger or block the signature if key phrases are present in email subject or body, base the rule on attachment properties, message type, etc.

To view the full list available conditions go to: https://technet.microsoft.com/en-us/library/dd638183%28v=exchg.150%29.aspx

Note, that exceptions are created by prefixing a Shell name of a condition with "ExceptIf", e.g. ExceptIfFrom.

For instance, the below script utilizes the uploaded HTML code to create an email signature policy that will be applied to outgoing emails sent by the Marketing department:
 
New-TransportRule -Name "External signature for Marketing Department" -SentToScope 'NotInOrganization' -SenderADAttributeContainsWords "Department:Marketing" -ApplyHtmlDisclaimerText "$signature"

Open in new window


That's all. Good luck!
1
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
0 Comments

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month