• Adonay Palacios
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi,

The following links shows how to attach pdf and send email using Apex code

http://www.salesforce.com/us/developer/docs/pages/Content/pages_email_sending_attachments.htm

The part in the article given at end of my post reads a pdf and set its content as attachment.But this example only shows how to attach VisualForce page which is renderd as PDF.

 

When I tried same example code with a PDF file hosted on some other server and is public(Say: http://myserver.com/myFile.pdf). The VisualForce page runs without error, but does not give any response. Doesn't Apex attaching external files as attachment with email. If Not is there any other workaround. The problem is I want to attach a PDF which is hosted on some other server and send email using Apex. 

 

 

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        // Reference the attachment page and pass in the account ID
        PageReference pdf =  Page.attachmentPDF;
        pdf.getParameters().put('id',(String)account.id);
        pdf.setRedirect(true);

        // Take the PDF content
        Blob b = pdf.getContent();

        // Create the email attachment
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName('attachment.pdf');
        efa.setBody(b);