Page 1 of 1

Add Reply-To header for Distribution List

Posted: 2005-07-28 16:25
by cristiano
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

Re: Add Reply-To header for Distribution List

Posted: 2006-07-24 15:31
by peter_mcc
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)

Posted: 2006-07-24 20:22
by ^DooM^

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

Posted: 2006-07-24 23:43
by peter_mcc
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

Re: Add Reply-To header for Distribution List

Posted: 2008-04-16 18:45
by gsmaclean
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

Re: Add Reply-To header for Distribution List

Posted: 2009-01-24 18:51
by andyp
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.