You need to sign in to do that
Don't have an account?
Jayesh Babu A V
How to send email from salesforce apex class with a link in the email body?
I have created the following string:
When I copy and paste this string on a html file, the Click Here part is turning into a link, which when clicked, the compose window of the Live Mail is opening up with subject and body is already filled with replysubject and replyBody values. But, I want this string to be sant as an email. So, I used this code:
I am getting the email fine, but in the email body, the Click Here part is no longer a link. But when i use raw strings instead of variables, like this:
And when I tried like this:
So, what am I doing wrong? How can I send an email with link in the email body?
String emailBody = 'Dear customer, <br/><br/>Click on the following link to send reply. <a href="mailto:'+ replyMail +'?subject='+replysubject+'&body='+replyBody+'">Click Here</a> Thanks.'
When I copy and paste this string on a html file, the Click Here part is turning into a link, which when clicked, the compose window of the Live Mail is opening up with subject and body is already filled with replysubject and replyBody values. But, I want this string to be sant as an email. So, I used this code:
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.toAddresses = new String[] { emailId }; message.optOutPolicy = 'FILTER'; message.subject = emailSubject; message.setSenderDisplayName(senderDisplay); message.setReplyTo(replyMail); message.setHtmlBody(emailBody); Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
I am getting the email fine, but in the email body, the Click Here part is no longer a link. But when i use raw strings instead of variables, like this:
<a href="mailto:'+ replyMail +'?subject=replysubject&body=replyBody">Click Here</a>its a link.
And when I tried like this:
<a href="mailto:'+ replyMail +'?subject="'+replysubject+'"&body="'+replyBody+'"">Click Here</a>its still a link, but the replysubject and replyBodyvalues are null.
So, what am I doing wrong? How can I send an email with link in the email body?
Mailto is generally used in the below format. Can you try using the below format and see if you are able to send an email with the link the email body
Reference: http://https://help.salesforce.com/apex/HTViewSolution?urlname=How-do-I-add-an-email-link-in-an-email-template-1327109106048&language=en_US
And if you are using bind variables, the string should be used like this example below
Anudeep