Email Signature Placement Script

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Email Signature Placement Script

Post by modiX » 2016-03-07 03:31

Basically, when you reply to any mail in any client, hMailServer will place the auto signature at the very end of the mail down below the quote of the person you are replying to. The aim of this script is to modify the email and place the signature right before the quote, if possible.

The real problem on this attempt is, there is no common way to find out when a quote starts in a mail, because the HTML vary depending on the email client that is used to reply.

With your help I want to expand this script to support all common email clients in most versions. Please read the comments of the code to see what clients are supported now.

Code here: View Script

The script is working by splitting off the signature from the content of the mail, first. After that it decleares all HTML snippets that can indicate a quote start. On the for-each iteration it will find the first match and insert the signature right before it. The last HTML snippet is "</body></html>", so a mail that does not contain any quote will simply insert the signature before the closing body tag.

When inserting the signature it will also wrap some HTML around it. This HTML uses tags and classes that will make sure the default font family and size will be set through CSS on all supporting clients.

Please feel free to use this script. If it does not work you might need to add another entry to the snippets array. You should also consider to make sure the signature got the right default font the email message uses by modifying the wrapped HTML of the signature.

Please report your edit and the email client that was used so we end up with a script that works on most email clients.

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-03-07 19:28

- Added support for Mozilla Thunderbird
- Added support for text signatures (read the comments)
- Bugfixes

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-03-08 13:40

I updated it again, so text mails from Thunderbird finally work. In the next updates I will include support for:
- Messages & Mail (iPhone)
- Mail for Windows 10
- Microsoft Outlook 2003

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-03-09 14:48

Another update, the following emails are supported now:

- HTML mails sent with Microsoft Outlook 2010 / 2016
- HTML mails sent with Microsoft Outlook Web App
- HTML mails sent with Microsoft Mail for Windows 10
- HTML mails sent with Mozilla Thunderbird
- TXT mails sent with Mozilla Thunderbird
- HTML mails sent with Messages & Mail for iPhone (German)
- HTML mails sent with Microsoft Outlook 2003 (there is still a known issue with the alignment at a test case at me)
- HTML mails sent with Microsoft Outlook 2010
- TXT mails sent with Microsoft Outlook (German)

Most clients include localized text in quotes of TXT mails, some even in HTML mails. This is a real problem, as we all are Germans and I don't have the time to install every client in English to see how the quote begin looks. I could solve this problem with regular expressions, but I fear it could fetch anything that is not meant to be a quote begin.

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-03-11 02:53

- Fixed the issue with Outlook 2003
- Handled appointment mails (only HTML mails will attach a signature)

User avatar
jimimaseye
Moderator
Moderator
Posts: 8066
Joined: 2011-09-08 17:48

Re: Email Signature Placement Script

Post by jimimaseye » 2016-03-11 17:54

Modix, just a thought (I hope you dont mind):

Your code opens with:

Code: Select all

	Dim domains : domains = Array("example.com") ' List of all domains, SMTP authentification must be enabled on local users

	For Each domain In domains
		If (InStr(oClient.Username, "@" & domain) > 0) Then
			isOutgoing = TRUE ' Mail is outgoing
			Exit For
		End If
	Next
.
.	
	If isOutgoing Then ' Only modify outgoing emails

In order to be universal and avoid the risk of 'forgetting' to add to your Array of domains any new domains that may be created, you could replace all the above and simply just use:

Code: Select all

	 If oClient.username <> "" then
The idea being that if oClient.username is not "" then it must be authenticated, and therefore must be an internal user and therefore sending out.
HMS 5.6.6 B2383 on Win Server 2008 R2 Foundation, + 5.6.7-B2415 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-03-13 13:44

jimimaseye wrote:In order to be universal and avoid the risk of 'forgetting' to add to your Array of domains any new domains that may be created, you could replace all the above and simply just use:

Code: Select all

	 If oClient.username <> "" then
The idea being that if oClient.username is not "" then it must be authenticated, and therefore must be an internal user and therefore sending out.
Oh, I'm very new to mail servers at all. What if the sender is authenticated on a foreign SMTP server? I thought oClient.username it would contain the sender emails when authenticated anywhere ...

User avatar
jimimaseye
Moderator
Moderator
Posts: 8066
Joined: 2011-09-08 17:48

Re: Email Signature Placement Script

Post by jimimaseye » 2016-03-13 13:48

The username is the username of the account on hmailserver that they used to authenticate with. It doesnt matter where they are in the world, or what client they are using - they can only authenticate to hmailserver with hmailserver credentials (accounts). Therefore when authenticated, it will always be by one of your users/clients and they will be the ones sending (assuming you DONT have allow External to External allowed, which dont of course. :wink: )

Foreign smtp servers do not authenticate with your server when sending INBOUND emails. Any other smtp servers authenticating to your server (such as other servers in your network) will, just like clients, be given your hmailserver credentials to do so (and therefore authorised by you).
HMS 5.6.6 B2383 on Win Server 2008 R2 Foundation, + 5.6.7-B2415 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-03-13 13:51

jimimaseye wrote:The username is the username of the account on hmailserver that they used to authenticate with. It doesnt matter where they are in the world, or what client they are using - they can only authenticate to hmailserver with hmailserver credentials (accounts). Therefore when authenticated, it will always be by one of your users/clients and they will be the ones sending (assuming you DONT have allow External to External allowed, which dont of course. :wink: )

Foreign smtp servers do not authenticate with your server when sending INBOUND emails.
Thank you! I will consider this and implement it on my next update. :)

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-03-16 22:32

- Optimized code based on jimimaseye post
- Added support for Thunderbird (German)

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-03-19 23:09

- Added support for RainLoop (web mail client)
- Fixed a compatibility bug with Thunderbird

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-05-31 15:55

- Added support for AquaMail

User avatar
modiX
Normal user
Normal user
Posts: 41
Joined: 2016-03-06 21:21

Re: Email Signature Placement Script

Post by modiX » 2016-10-26 03:27

- Fixed Text mails
- Added support for Outlook English (newer versions)

Post Reply