You need to sign in to do that
Don't have an account?
case comments
setReplyTo not working correctly
I have code that redirects emails and sets the from address to the original email address. It will take the from address on the email and stick it into the reply to, so when the recipient gets it, it'll be as if it came from the original sender and they can reply back to them. The code has been working for years but something happened and now it's not working. Nothing has changed, and I can only suspect that it was due to a Salesforce release. Does anybody know what I would need to change to get this to work again? Thanks.
public with sharing class ForwardEmailController { public EmailMessage email {get;set;} public String forwardTo{get;set;} public ForwardEmailController(){ String id = Apexpages.currentPage().getParameters().get('e'); if (id != null){ email =[Select id,ParentId,subject,FromName,FromAddress,TextBody,HtmlBody from EmailMessage where id =: id]; } } public pageReference forward(){ List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>(); String delimiter = ';'; if (forwardTo!= null && forwardTo!=''){ if (forwardTo.indexOf(',')!= -1){ delimiter = ','; } for (String s : forwardTo.split(delimiter)){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(new String[] {s}); mail.setSenderDisplayName(email.FromName); mail.setSubject(email.subject); mail.setReplyTo(email.FromAddress); mail.setPlainTextBody(email.TextBody); mail.setHtmlBody(email.HtmlBody); emailList.add(mail); } Case c = [Select id,redirected__c from Case where id =: email.ParentId][0]; c.Redirected__c = true; update c; Messaging.sendEmail(emailList); } return new PageReference('/' +email.ParentId); } }
Turned out it was our email service that was stripping off the ReplyTo address.