You need to sign in to do that
Don't have an account?
Email formatting in apex
Hi,
I am developing a component that send emails to a list of recipients via an apex code.
Here is my setup:
1) I create an object MyEmail which has email body some text
2) When I save this record I have trigger which calls my routine to send the email and everything works like a charm no problem....
Here is the issue:
MyEmail object is a a child to a case, so when I create a new EmailObject and send it I append the previous EmailObject messages and send them ti tge recipients as a digest email.
When I send the email however everything come in on line with no formatting whatsoever...
Any help will be appriciated.
Here are pieces of my Apex code:
This appends all the prior message and returns a string which I send from the second block of code
private static String appendPriorUpdates(String latestNotif, Notification__c notif, List<Notification_Message__c> prior, Boolean html){ String emailBody = latestNotif; for(Notification_Message__c nm :prior){ String tempMsgBody = ''; if(html){ tempMsgBody += '<p> Sent: ' + nm.Timestamp__c + ' | By: ' + nm.CreatedBy.Name + '</p></br>'; tempMsgBody += '<p>' + nm.Message__c + '</p>'; }else{ tempMsgBody += 'Sent: ' + nm.Timestamp__c + ' | By: ' + nm.CreatedBy.Name + ''; tempMsgBody += nm.Message__c; } emailBody += tempMsgBody; } /* Append the initial notification email */ emailBody += '<p>Initial Notification</p>'; emailBody += ('<p> ' + notif.Notification_Sent_Hist__c + '</p>'); emailBody += ('<p>' + notif.Notification_Reason__c + '</p>'); return emailBody; }
Here is where I send the email:
mail.setSenderDisplayName('My Name'); mail.setReplyTo('recipeint@somewhere.com'); //mail.setBccSender(true); mail.setUseSignature(false); mail.setSubject('My Notification :: ' + notif.Subject__c); //mail.setHtmlBody(appendPriorUpdates(strNotificationMessage, notif, priorUpdates, true)); mail.setPlainTextBody(appendPriorUpdates(strNotificationMessage, notif, priorUpdates, false));
Thanks in advance.