Checking if an inbound email has an attachment

paulsena
Kilo Contributor

Hi,

Below is a snippet that you can use to check if an email has an attachment.
This particular example is used from an inbound email action.


//Query the sys_email table so we can get the logged email's sys id, this is used later to look for attachments.
var email_log = new GlideRecord('sys_email');
email_log.addQuery('uid', email.uid); //Since we are calling this from an inbound email action, we need to lookup this incoming uid in the sys_email table.
email_log.query();

//Make sure we can find the email in the email log
if (email_log.next()) {

//Query our attachment table
var attachLog = new GlideRecord('sys_attachment');
attachLog.addQuery('table_sys_id', email_log.sys_id);
attachLog.addQuery('table', 'sys_email');
attachLog.query();

if (attachLog.next()) {
//Do Stuff
}

}

4 REPLIES 4

lawrence_eng
Administrator
Administrator

Thank you for sharing!


adiddigi
Tera Guru

Thanks !


Milan11
Tera Contributor

Helpful, thank you.

martakostecki
Tera Contributor

Worked like a charm. Thank you