COM Messages.ItemByDBID
COM Messages.ItemByDBID
Is there a way to get to Messages.ItemByDBID without going through domain>account>imapfolders? I'm working on something where the message ID is known, but the rest is not.
Re: COM Messages.ItemByDBID
How are you getting the message?
If from From a rule or built in event?
Or from a file in the data store?
If from From a rule or built in event?
Or from a file in the data store?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: COM Messages.ItemByDBID
The idea behind it is some kind of bounce/ unsubscribe handling. Right now I'm working on the unsubscribe part.
The message ID gets inserted into a mailto link in a list-unsubscribe header at OnDeliveryStart. Then if the subscriber unsubscribes, the message id gets parsed from the to address to find the list so the from address can be deleted from the distribution list.
I sort of worked around the issue already by using the list name in the mailto instead of message ID. However, I stil think the exercise could be useful. I'm sure it will come in handy if it's possible.
Re: COM Messages.ItemByDBID
Here's what I have for the insert.
I have the address parsing and deleting from the distribution list worked out already. I prefer to use only the message ID if for no other reason than a bit more anonymity/randomness.
Code: Select all
Sub OnDeliveryStart(oMessage)
REM - Add List-Unsubscribe header if sending to distribution list
Dim hMSCOM, sDomain, sDistList, sDistListRecip, IsDistList, vDomainName
vDomainName = Split(oMessage.Recipients(0).OriginalAddress, "@")(1)
Set hMSCOM = CreateObject("hMailServer.Application")
Call hMSCOM.Authenticate(ADMIN, PASSWORD)
Set sDomain = hMSCOM.Domains.ItemByName(vDomainName)
Set sDistList = sDomain.DistributionLists.ItemByAddress(oMessage.Recipients(0).OriginalAddress)
If oMessage.Recipients(0).OriginalAddress = sDistList.Address Then
Dim vListName : vListName = Replace(oMessage.Recipients(0).OriginalAddress, "@", "=")
oMessage.HeaderValue("List-Unsubscribe") = "<mailto:unsubscribe+" & oMessage.ID & "-" & vListName & "@mydomain.net>"
oMessage.Save
End If
End Sub
Re: COM Messages.ItemByDBID
Won't the unsubscribe message come FROM that account that want's to be unsubscribed...
Otherwise someone else could unsubscribe for others by guessing original message IDs
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: COM Messages.ItemByDBID
I need a unique key of some kind. Message ID works as well as any. Could be any random string.
1) send unique identifier within list-unsubscribe mailto header plus www link also.
2) insert into body of message the www link (or mailto with instructions or something)
3) if recipient clicks link or sends unsubscribe message --> use unique identifier to find list and recipient in order to unsubscribe.
Message ID is not so important now since I discovered that hm_messages and hm_message_metadata do NOT contain the list recipient (member) address! Unbelievable! The list address is shown in column metadata_to for all list recipients.
Due to that, I guess I'll just use a random string and record it into a new database table along with the list name, recipient, etc. That can be retrieved when called by rule. I wanted to avoid setting up another database (makes sharing here just that much more complex), but it looks like there's no choice.
Last edited by palinka on 2020-05-16 23:41, edited 1 time in total.
Re: COM Messages.ItemByDBID
One other thing. Minor but annoying. In order to see if the message recipient is a distribution list, I use this:
This works fine, but throws an error when the recipient is NOT a distribution list: Subscript out of range.
I tried putting sDomain.DistributionLists.ItemByAddress(oMessage.Recipients(0).OriginalAddress) within an IF statement, but that didn't work. Is there a better way to mute these errors?
Code: Select all
Set hMSCOM = CreateObject("hMailServer.Application")
Call hMSCOM.Authenticate(ADMIN, PASSWORD)
Set sDomain = hMSCOM.Domains.ItemByName(vDomainName)
Set sDistList = sDomain.DistributionLists.ItemByAddress(oMessage.Recipients(0).OriginalAddress)
If oMessage.Recipients(0).OriginalAddress = sDistList.Address Then
I tried putting sDomain.DistributionLists.ItemByAddress(oMessage.Recipients(0).OriginalAddress) within an IF statement, but that didn't work. Is there a better way to mute these errors?
Re: COM Messages.ItemByDBID
Well, the whole thing is up in the air. I need each message to distribution list recipients (members) to have a unique identifier but I don't believe there is a way to access individual messages from the distribution list to the distribution list MEMBERS. I can only access the message going to the distribution list from the original sender at OnDeliveryStart. I assume OnDeliverMessage is the same (haven't tried).
I guess this is why php mailing list software exists.
I can make the unsubscribe work this way (as it is above) with a mailto link in list-unsubscribe because the mailto link can contain the distribution list address and the unsubscribe from is obviously the list member. But no www unsubscribe unless I can insert a unique ID into each member's message.
I guess this is why php mailing list software exists.

I can make the unsubscribe work this way (as it is above) with a mailto link in list-unsubscribe because the mailto link can contain the distribution list address and the unsubscribe from is obviously the list member. But no www unsubscribe unless I can insert a unique ID into each member's message.