Page 1 of 1

Need to save a copy of the incoming email as an attachment

Posted: Fri Sep 15, 2023 8:10 pm
by RobAtWork
Script URL: Internal Only
Version of script: 3.4.3
Hosting company: Dedicated server
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: eml/imap/email attachment/etc.

Write your message below:

We are using the OAUTH mechanism against O365. Everything works as spec'd

However, We have a requirement to retain the original email not just create a ticket from it. I don't believe an export option would work as it is no longer the original email.

My thought is that the GRAPHAPI that parses the new message could be used to not just parse the subject, body, etc. but to grab the whole message as an EML and attach it as a separate attachment once the ticket is created.

I'm wondering if anyone has done this (maybe I'm missing something). Failing that, maybe point me in the right direction as to where I can make the appropriate change. After a quick review (and I do mean quick), I'm thinking that I need to alter the 'attachments.inc.php' file.

Any advise would be appreciated.

Re: Need to save a copy of the incoming email as an attachment

Posted: Fri Sep 15, 2023 8:14 pm
by Klemen
The incoming mail is saved to a (temporary) file by the save_forward_mail function in /inc/mail/email_parser.php - you can plug in your own code there to save a copy to your desired destination.

However, the recommended way is to keep original emails in your mailbox instead. In the Admin panel > Settings > Email under IMAP Fetching you can turn "Keep a copy" on (save changes). This way Hesk will keep all the emails in your O365 mailbox, just mark them as read/viewed.

Re: Need to save a copy of the incoming email as an attachment

Posted: Fri Sep 15, 2023 8:25 pm
by RobAtWork
I'll check that php file out. thanks.

I'm using an E3 Licensed account with legal hold so even deleted mails are recoverable in my O365. However, the workflow that we are automating with HESK requires repeated interaction with the actual email so sending people back to Outlook would defeat the purpose of using HESK.

Thanks,
Rob

Re: Need to save a copy of the incoming email as an attachment

Posted: Thu Oct 12, 2023 2:48 pm
by wweerrbb
Klemen wrote: Fri Sep 15, 2023 8:14 pm The incoming mail is saved to a (temporary) file by the save_forward_mail function in /inc/mail/email_parser.php - you can plug in your own code there to save a copy to your desired destination.

However, the recommended way is to keep original emails in your mailbox instead. In the Admin panel > Settings > Email under IMAP Fetching you can turn "Keep a copy" on (save changes). This way Hesk will keep all the emails in your O365 mailbox, just mark them as read/viewed.
Hi there, I have the similar issue, my question is if define('HESK_IMAP'), function save_foward_mail never gets called, hence it won't save any copy of the email. Am I missing something?

Re: Need to save a copy of the incoming email as an attachment

Posted: Fri Oct 13, 2023 11:21 am
by Klemen
It's not as easy as defining define('HESK_IMAP') to make it work; you will need your own PHP code to perform what you need. Consider hiring a PHP developer for help if you aren't able to figure it out yourself.