Change Header From, To, CC, BCC

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
Wichert
New user
New user
Posts: 7
Joined: 2019-10-07 15:02

Change Header From, To, CC, BCC

Post by Wichert » 2020-02-14 11:23

Hello,

i am searching for the terms to change the Header information.
My wish is to take a Mail and change the From, To, CC, BCC address.
What i know is that ich can change the to address with "oMessage.ClearRecipients" and than add the new with "oMessage.AddRecipient".

Maybe i have the wrong terms for the others.
"oMessage.FromAddress" dont change the From.

Here my little try

Code: Select all

Sub TEST(oMessage)
    oMessage.ClearRecipients()
    Call oMessage.AddRecipient("test1", "test1@test.com")
	oMessage.FromAddress = "no-reply@test.com"
	oMessage.Subject = "TEST"
    oMessage.Save
End Sub
I hope someone can help me or can say that isnt possible.

Kind Regards Niels

User avatar
mattg
Moderator
Moderator
Posts: 20548
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Change Header From, To, CC, BCC

Post by mattg » 2020-02-14 13:51

oMessage.FROM is the SMTP envelope From not the mail header From

You should be changing the mail header from

See here for an example
https://www.hmailserver.com/forum/viewt ... er#p153204
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Wichert
New user
New user
Posts: 7
Joined: 2019-10-07 15:02

Re: Change Header From, To, CC, BCC

Post by Wichert » 2020-02-17 14:10

Hi,

thanks for your help.

I tried this code:

Code: Select all

Sub Salden(oMessage)
    Dim sToHeader 
	sToHeader = oMessage.HeaderValue("To")
	oMessage.ClearRecipients()
	oMessage.AddRecipient() = sToHeader
	oMessage.HeaderValue("To") = sToHeader
	oMessage.Save
End Sub
First i want to save the Original "TO" and than delete all Recipients included the BCC.
At the end i want back the Original "TO".

The Header information is correct but i think im Lost the Envelop Information.
I see in my Logs that the Hmailserver did not send a Mail.
Could someone say what i need for this Option.

Wichert
New user
New user
Posts: 7
Joined: 2019-10-07 15:02

Re: Change Header From, To, CC, BCC

Post by Wichert » 2020-02-17 14:50

Sorry guys,

i have found my fault.

This code works for me.

Code: Select all

Sub Salden(oMessage)
    Dim sToHeader 
	sToHeader = oMessage.HeaderValue("To")
	oMessage.ClearRecipients()
	Call oMessage.AddRecipient("",sToHeader) 
	oMessage.Save
End Sub
I think

Code: Select all

Call oMessage.AddRecipient("",sToHeader)
can change to

Code: Select all

oMessage.AddRecipient "",sToHeader
but i didnt test it.

In this Case my Original "TO" is Still alive an all BCC Recipients are deleted. Thats waht i want.

Thanks for you Help

Post Reply