You need to sign in to do that
Don't have an account?
Unable to view PDF when send an email with attach PDF
Hi guys,
when i am sending an email through Messaging.singleEmailMessage(Outbound Email) with attach pdf, unable to view pdf due to improper content type. I am not using the renderAsPdf content which is available in doc(Apex code documentation)
only set the data in attachment body of two textbox data.Anyone help me out to resolve this issues
public String subject { get; set; }
public String body { get; set; }
String inputStr = subject + body;
Blob inputdata = Blob.valueOf(inputStr);
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setContentType('application/pdf');
efa.setFileName('attachment.pdf');
efa.setBody(inputdata);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddresses = addresses.split(':', 0);
email.setSubject( subject );
email.setToAddresses(toAddresses);
email.setPlainTextBody(Msg);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
// Sends the email
Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
Regards
saurabh
I think the inputdata you are supplying is in incorrect format.
Try get the blob content from a vf page instead. I haven't tried it, hopefully it should work.
Hope that helps.
Afzal
i donot want the blob content directly from visual force page so my requirement is to set the blob content which is coming from two textbox and pass into the setbody(b).
string inputdata = string1+string2;
blob b= blob.valueOf(inputdata);
efa.setbody(b);