Get HTML to pull information from AD to generate an email signature

Hi Experts,

I have created an HTML signature and worked hard on the format. Active directory attributes should be pulled in order to generate the signature details. when I run the code, I get the format I want but nothing is pulled from AD.

This code did run ok when I used as a disclaimer rule on office 365.

I have attached the code, can someone guide me on how to make the HTML code pull the attribute from AD.

I did connect to AD via powershell and tried to run the code but no luck.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Email Signature</title>




<div style="font-size:9pt;  font-family: 'Helvetica',sans-serif;">

<br> </br>

<p><strong><img src=" " width="174" height="37" alt="" /></strong></p><br>

<strong>%%Displayname%%</strong> / %%title%% <br>  

<a href="mailto:%%email%% "><font color="#D01f29">%%email%%</font></a><br />


<strong>%%Company%%</strong> <br>  

%%Phonenumber%% <br>  

%%Street%% <br>  

%%City%%, %%State%%,%%Zipcode%%, %%Country%% <br>  

<a href="" target="_blank"><font color="#D01f29"></font></a> <br />


<a href="" target="_blank"><img src="" alt="" width="24" height="24" border="0" /></a>&nbsp; <a href="" target="_blank"><img src="" alt="" width="24" height="24" border="0" /></a>&nbsp; <a href=";trkInfo=clickedVertical%3Acompany,clickedEntityId%3A33883,idx%3A2-1-4,tarId%3A1439926026058,tas%3Acompany" target="_blank"><img src="" alt="" width="24" height="24" border="0" /></a><br><br>

<em>This email may contain confidential  and/or proprietary information. Access to this e-mail by anyone other than the  intended recipient is unauthorised. If you are not the intended recipient (or responsible  for delivery of the message to such person), you may not use, copy, distribute  or deliver this message or any of its contents to anyone or take any action in  reliance on it</em>



Open in new window

Abbas HaidarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi there,

Can you confirm where you are running the code please? You mentioned it worked in an Office 365 transport rule and as this question is tagged with ‘Office 365’, we just want to find out where this is not working.

All the best,

Abbas HaidarAuthor Commented:
Basically, the aim is to get the users to run the .html code in order to generate their email signature on their desktop ( office 365 was an example to prove that the code works if connected to AD, I will take that tag out). It will be ideal to have this as a page where a user enter his username and password and it will generate his signature according to his AD credentials.
Unfortunately the above will not work. It will simply open a HTML page showing either the design or the flat code. You won't be able to simply run an HTML file like you can a PowerShell command. To run something like this over PowerShell, you will need to use PowerShell commands to query your AD and build your signature.

You could always try one of our email signature solutions to do make this process easier if you were interested in looking at a third-party product.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Abbas HaidarAuthor Commented:
Thank you, I dont want to use a third party. I am looking to use PowerShell commands to query AD and build your signature using the html format as an output. is that possible?
CodeTwo SoftwareSoftware DeveloperCommented:
Hi Abbas,

It will be ideal to have this as a page where a user enter his username and password and it will generate his signature according to his AD credentials.

This sounds like it would require a whole online application. Before you go this route, see if the VBS solution mentioned by Shaun is close enough.

Alternatively, you could try this:

1. Deploy an Office 365 disclaimer using your code (, but configure it to be added only to the first email.

You can do this by defining an exception: Except If > The subject or body matches these text patterns > "This email may contain confidential  and/or proprietary information"

2: Ask users to send 1 email to themselves and copy the disclaimer into the email signature box on their email clients BUT set it to add only to replies and forwards (

You can also send this email automatically using PowerShell:

foreach ($AllMailboxes in (Get-Mailbox)) { $Name=$AllMailboxes.Name; $UserSMTP=$AllMailboxes.PrimarySmtpAddress; send-mailmessage -to "$Name <$UserSMTP>" -from "$Name <$UserSMTP>" -subject "Email signature + instructions" -bodyasHTML -body "%instructions%" -smtpServer %Your SMTP server FQDN% }

Open in new window

Best regards,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.