I have a need to create a drop mailbox. Messages received at this mailbox would be written to a file for further processing. I used to do this with an IIS SMTP "local" domain. Messages sent to the local domain would just get written in RFC 822 format into the mailroot\drop directory.
Now I'd like to emulate that functionality with an HMS script as a rule action. I see I can code it by accessing the many properties exposed by the Message class, but I rather just copy the .eml file underlying the Message instance. I see these filenames are exposed in the Queue object, but I don't see a way to access the filename via Message properties or methods.
Any ideas?
Script to write message to file
Re: Script to write message to file
filename is a Message property
https://www.hmailserver.com/documentati ... ct_message
Depends on when you call it, or how you find your message
You could use this property during OnDeliveryStart or OnAcceptMessage if you wanted to catch current messages live
You could also iterate through the domains > Accounts > IMAP Folders > Messages to get your message
https://www.hmailserver.com/documentati ... ct_message
Depends on when you call it, or how you find your message
You could use this property during OnDeliveryStart or OnAcceptMessage if you wanted to catch current messages live
You could also iterate through the domains > Accounts > IMAP Folders > Messages to get your message
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
- jimimaseye
- Moderator
- Posts: 8917
- Joined: 2011-09-08 17:48
Re: Script to write message to file
Take a look at this. Palinka did some good work and maybe there are some useful bits in there to help you. https://www.hmailserver.com/forum/viewtopic.php?t=33062
5.7 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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
-
- Senior user
- Posts: 390
- Joined: 2016-12-08 02:21
Re: Script to write message to file
Excellent. I don't know how I missed that in the docs. I do see it is there know.mattg wrote: ↑2020-12-08 23:31filename is a Message property
https://www.hmailserver.com/documentati ... ct_message
Depends on when you call it, or how you find your message
You could use this property during OnDeliveryStart or OnAcceptMessage if you wanted to catch current messages live
You could also iterate through the domains > Accounts > IMAP Folders > Messages to get your message
I plan to keep this simple. Regular mailbox with two rules that match all messages. First one has action to fire script to write to file, second deletes the email.
Re: Script to write message to file
Add this to Eventhandlers.vbs:mikedibella wrote: ↑2020-12-08 23:00I have a need to create a drop mailbox. Messages received at this mailbox would be written to a file for further processing. I used to do this with an IIS SMTP "local" domain. Messages sent to the local domain would just get written in RFC 822 format into the mailroot\drop directory.
Now I'd like to emulate that functionality with an HMS script as a rule action. I see I can code it by accessing the many properties exposed by the Message class, but I rather just copy the .eml file underlying the Message instance. I see these filenames are exposed in the Queue object, but I don't see a way to access the filename via Message properties or methods.
Any ideas?
Code: Select all
Sub MailDrop(oMessage)
With CreateObject("Scripting.FileSystemObject")
.CopyFile oMessage.Filename, "C:\mailroot\drop\", True
End With
End Sub
Don't forget to create the directory "C:\mailroot\drop"
Monitoring the folder is another matter ... A suggestion is here...
https://stackoverflow.com/questions/365 ... o-a-folder
SørenR.
Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.
Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.
-
- Senior user
- Posts: 390
- Joined: 2016-12-08 02:21
Re: Script to write message to file
Thanks to all who responded. I think I'm all set now.
Re: Script to write message to file
I was toying around with this and found out that messages in a folder apparently always iterate in date order from oldest to newest. So if you have to call up the message from outside eventhandlers, you can always just pull the last iteration. Skip all the others.
Message = Folder.Messages.Item(Folder.Messages.Count - 1)
FileName = Message.FileName
Disclaimer - I do not know FOR SURE that the iteration is ALWAYS in date order, but it does appear to be that way based on the few folders I was messing around with.
Message = Folder.Messages.Item(Folder.Messages.Count - 1)
FileName = Message.FileName
Disclaimer - I do not know FOR SURE that the iteration is ALWAYS in date order, but it does appear to be that way based on the few folders I was messing around with.