You need to sign in to do that
Don't have an account?
Anand@SAAS
Mail.setReplyTo not working???
Tried the following in "Execute anonymous":
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setReplyTo('someemail@gmail.com'); mail.setSenderDisplayName('Sender Name'); mail.saveAsActivity=false; mail.setToaddresses(new List<String>{'recipient@gmail.com'}); mail.setTemplateId('00XQ0000000QH2B'); mail.setTargetObjectId('00580000001gXtK'); mail.setUseSignature(false); Messaging.sendEmail(new List<Messaging.Email>{mail});
The email is received successfuly by when I "hit" reply it show s the email address of the "Admin" user that I executed the above code with. Should it not be "someemail@gmail.com"?
Please check reply to email mentioend in the template you are refering in your code.
All Answers
Please check reply to email mentioend in the template you are refering in your code.
That did do the trick. But that makes "setReplyTo" useless when using templates.
we need to decide where we want to use replyto.. or write that template also as VF page and it may meet ur requirement.
Hi I tried to use without template too , but its still not working , when I hit the reply it goes to admin email Id :
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {'myemail@gmail.com'});
mail.setReplyTo('test@gmail.com');
mail.setSenderDisplayName('Batch Processing');
mail.setSubject('Batch Process Completed');
mail.setPlainTextBody('Batch Process has completed');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Any Idea ?
- Navigate to Setup>> Organization-Wide Email Addresses and create a record with Email address which you would like to use it as ReplyTo for Email Notification.
- In the Apex code, query this record and set its ID to setOrgWideEmailAddressId attribute as shown below.
List<OrgWideEmailAddress> orgWideEmailLst = [select id, address from OrgWideEmailAddress where displayname = :'No Reply' limit 1];String orgWideEmailId = orgWideEmailLst.size()>0?orgWideEmailLst[0].id:'no-reply@email.com';
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setOrgWideEmailAddressId(orgWideEmailId);
mail.setSubject('My Email Subject');
mail.setHtmlBody('My Email Content');
List<String> sendTo = new List<String>();
sendTo.add('sampleTo@email.com');
mail.setToAddresses(sendTo);
mails.add(mail);
Messaging.sendEmail(mails);