Add inbound and outbound email to email client

Prudhvi Raj4
Tera Guru

Hi Team,

I have a requirement to add the all inbound and outbound emails when user tries to sends email from email client for that I have created email client template in which where I was calling the email script to get all the emails for the particular record.

Email script code

var gr = new GlideRecord("sys_email");
gr.addQuery("instance",current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
while(gr.next()){
         template.print(gr.getValue('body'));
}

The above code brings all the emails and show on the email client but the issue is with alignment, it just copy paste the email body but no proper table format/breaks/lines are followed. 

Is there away to show all the email is proper format?

 

Regrads,

Prudhvi 

1 ACCEPTED SOLUTION

Anand Kumar P
Giga Patron
Giga Patron

Hi @Prudhvi Raj4 ,

Within the script, you should iterate through the emails and transform line breaks into <br> tags. These <br> tags are essential in HTML for creating line breaks and formatting email content.

 

 

var gr = new GlideRecord("sys_email");
gr.addQuery("instance", current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
var emailContent = "";
while (gr.next()) {
    var emailBody = gr.getValue("body");
    emailBody = emailBody.replace(/\n/g, "<br>"); 
    emailContent += "<div style='border: 1px solid #ccc; padding: 10px; margin: 10px;'>" + emailBody + "</div>";
}

template.print(emailContent);

 

 

Please mark it as solution proposed and helpful if it works for you.

Thanks,

Anand

View solution in original post

3 REPLIES 3

Aniket Bhanse
Tera Guru

@Prudhvi Raj4 this may not be possible since your "body" field has the HTML data in it. Along with this, the outbound email sent contains Table/Images/Different size of Text.

 

Let me know if this helps

Anand Kumar P
Giga Patron
Giga Patron

Hi @Prudhvi Raj4 ,

Within the script, you should iterate through the emails and transform line breaks into <br> tags. These <br> tags are essential in HTML for creating line breaks and formatting email content.

 

 

var gr = new GlideRecord("sys_email");
gr.addQuery("instance", current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
var emailContent = "";
while (gr.next()) {
    var emailBody = gr.getValue("body");
    emailBody = emailBody.replace(/\n/g, "<br>"); 
    emailContent += "<div style='border: 1px solid #ccc; padding: 10px; margin: 10px;'>" + emailBody + "</div>";
}

template.print(emailContent);

 

 

Please mark it as solution proposed and helpful if it works for you.

Thanks,

Anand

Hi @Prudhvi Raj4 ,

Please consider marking it as helpful for the benefit of future readers.

Thanks,

Anand