- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 10:25 AM
Hi Team,
Is it possible? Export email from sys_email to sys_attachment in ".eml" format?
Thank's in advanced
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 07:57 PM
Hi @Rafael Batistot ,
try this
var current = new GlideRecord("sys_email");
if (current.get("dd2adb63c3916a10051cb132b401318c")) { // get the sys_email record that you want to convert as an attachment
gs.info(current.getDisplayValue());
}
//content of the mail
//I have used template literals `` for this to work enable es6 on you script or use string concatinaiton(+)
var content = `${current.headers}
------=_Part_103_1432489236.1740299923118
Content-Type: multipart/alternative;
boundary="----=_Part_104_1164394642.1740299923118"
------=_Part_104_1164394642.1740299923118
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=UTF-8
${current.body}
------=_Part_104_1164394642.1740299923118--`;
var attachment = new GlideSysAttachment();
//set up inputs
var rec = new GlideRecord('incident');
rec.get('197ed7e7c3916a10051cb132b40131fb');
var fileName = 'testEmail.eml';
var contentType = ' message/rfc822';
var agr = attachment.write(rec, fileName, contentType, content) // this attaches the email to target record in this case it is
I have taken example sys_email and incident record
I have added few comments too
adjust this as per your requirement
result
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 10:54 AM
Hi @Rafael Batistot ,
I have tried this
use GlideSysAttachment and build proper content from sys_email
you should be able to create .eml files
var current = new GlideRecord("sys_email");
if (current.get("74f36a58c3ad2e10051cb132b401310b")){
gs.info(current.getDisplayValue());
}
var attachment = new GlideSysAttachment();
//set up inputs
var rec = new GlideRecord('incident');
rec.get('c3e0778cc3146e10051cb132b40131b2');
var fileName = 'test.eml';
var contentType = ' message/rfc822';
var content = current.body;
var agr = attachment.write(rec, fileName, contentType, content);
gs.info('The attachment sys_id is: ' + agr);
result
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 11:38 AM
Hi Chaitanya,
Thank you for your support. It works but in parts. The body coming but the header not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 07:57 PM
Hi @Rafael Batistot ,
try this
var current = new GlideRecord("sys_email");
if (current.get("dd2adb63c3916a10051cb132b401318c")) { // get the sys_email record that you want to convert as an attachment
gs.info(current.getDisplayValue());
}
//content of the mail
//I have used template literals `` for this to work enable es6 on you script or use string concatinaiton(+)
var content = `${current.headers}
------=_Part_103_1432489236.1740299923118
Content-Type: multipart/alternative;
boundary="----=_Part_104_1164394642.1740299923118"
------=_Part_104_1164394642.1740299923118
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=UTF-8
${current.body}
------=_Part_104_1164394642.1740299923118--`;
var attachment = new GlideSysAttachment();
//set up inputs
var rec = new GlideRecord('incident');
rec.get('197ed7e7c3916a10051cb132b40131fb');
var fileName = 'testEmail.eml';
var contentType = ' message/rfc822';
var agr = attachment.write(rec, fileName, contentType, content) // this attaches the email to target record in this case it is
I have taken example sys_email and incident record
I have added few comments too
adjust this as per your requirement
result
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya