Add Reply-To header for Distribution List

This section contains scripts that hMailServer has contributed with. hMailServer 4 is needed to use these.
Post Reply
cristiano
New user
New user
Posts: 9
Joined: 2005-07-27 05:16
Location: Curitiba/PR/Brazil

Add Reply-To header for Distribution List

Post by cristiano » 2005-07-28 16:25

For 4.1 or up versions only

Code: Select all

Sub OnDeliverMessage(oMessage)
 If InStr(oMessage.To, "distrlist@domain.com") Then 
  oMessage.HeaderValue("Reply-To") = "distrlist@domain.com"
  oMessage.Save()
 End If
End Sub

peter_mcc
New user
New user
Posts: 20
Joined: 2006-04-03 14:50
Location: Sydney, Australia

Re: Add Reply-To header for Distribution List

Post by peter_mcc » 2006-07-24 15:31

And if you want to change the subject to show it was from a list you can do that easily too!

I added the "LCase()" conversion - is it needed?

Code: Select all

Sub OnDeliverMessage(oMessage)
 If InStr(LCase(oMessage.To), "distrlist@domain.com") Then 
  oMessage.HeaderValue("Reply-To") = "distrlist@domain.com"
  If Not (InStr(lcase(oMessage.Subject), LCase("[List prefix]")) > 0) then
    oMessage.Subject = "[List prefix]" & oMessage.Subject
  end if
  oMessage.Save()
 End If
End Sub
Peter

(edited later a couple of times)
Last edited by peter_mcc on 2006-08-01 11:37, edited 4 times in total.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2006-07-24 20:22

Code: Select all

If InStr(LCase(oMessage.To, "distrlist@domain.com") Then
You are missing a matching brace.

Code: Select all

If InStr(LCase(oMessage.To, "distrlist@domain.com")) Then
-Jon

peter_mcc
New user
New user
Posts: 20
Joined: 2006-04-03 14:50
Location: Sydney, Australia

Post by peter_mcc » 2006-07-24 23:43

OOops. I actually meant to type

Code: Select all

If InStr(LCase(oMessage.To), "distrlist@domain.com") Then
ie convert the "to" field to lower case before doing the check.

Peter

gsmaclean
Normal user
Normal user
Posts: 47
Joined: 2008-04-16 18:35

Re: Add Reply-To header for Distribution List

Post by gsmaclean » 2008-04-16 18:45

Instr has a case-insensitive compare. You can write it as such:

Code: Select all

If InStr(1, oMessage.To, "distrlist@domain.com", vbTextCompare) Then
HOWEVER - as I discovered today, this can have unintended consequences if not watched carefully. If you have a user "jsmith@domain.com", and a list "smith@domain.com", it will incorrectly identify mail to "jsmith@domain.com" as being a list mail, because it contains the string "smith@domain.com".

There is no real perfect solution, but this is what I ended up using:

Code: Select all

Sub OnDeliverMessage(oMessage)

  If IsMessageToList(oMessage, "list1@domain.com") Then
    oMessage.HeaderValue("Reply-To") = "list1@domain.com"
    oMessage.Save
  End If

  If IsMessageToList(oMessage, "list2@domain.com") Then
    oMessage.HeaderValue("Reply-To") = "list2@domain.com"
    oMessage.Save
  End If

End Sub

Function IsMessageToList(oMessage, sList)

  IsMessageToList = False
  
  If LCase(oMessage.To) = LCase(sList) Then IsMessageToList = True
  If LCase(oMessage.CC) = LCase(sList) Then IsMessageToList = True

  If InStr(1, oMessage.To, "<" & sList & ">", vbTextCompare) Then IsMessageToList = True
  If InStr(1, oMessage.CC, "<" & sList & ">", vbTextCompare) Then IsMessageToList = True
  
End Function

andyp
Normal user
Normal user
Posts: 191
Joined: 2008-01-18 21:00

Re: Add Reply-To header for Distribution List

Post by andyp » 2009-01-24 18:51

I have a script doing the same. But be aware if you have an email to more than one distribution list, this won't work. I duplicate the msg and change it for every recipient.

Post Reply