1
  1. Summarize the problem

I am unable to attach a PDF file to an email to be sent to an email address. The PDF file is in the same folder as the HTML file, which contains the JavaScript code to send the email using SMTPJS.

Expected result: An email is sent to the designated email address with the pdf file without any problems.

Actual result: No email was sent at all.

  1. Describe what you’ve tried

#1: Attempt by putting file name and extension in quotes like this:

PFD_Articles.pdf -> 'PFD_Articles.pdf'

Again, the actual result is produced, not the expected one.

  1. Show some code
Email.send
(
    {
        Host: "smtp.gmail.com",
        Username: "sender@gmail.com",
        Password: "password",
        To: 'receiver@gmail.com',
        From: "sender@gmail.com",
        Subject: "<h1> ddd </h1>",
        Body: "And this is the body",
        Attachments:
            [
                {
                    name: 'PFD_Articles.pdf'
                }
            ]
    }).then
(
    alert("Successful! Please check your email inbox. Otherwise, you may have to enter your email address again.")
);
Weizhong Lee
  • 15
  • 1
  • 9

1 Answers1

0

     Email.send({
     Host: "smtp.gmail.com",
     Username : "abc@gmail.com",
     Password : "abc",
     To : receiver,
     From : "abc@gmail.com",
     Subject : emailSubject,
     Body : emailBody,
     Attachments : [
     {
      name : list.pdf
      data : pdfBase64 

     }]
     }).then(
     )
     });

This worked ! The created pdf got added to the email as an attachment

Khadim H.
  • 549
  • 5
  • 8
  • Then it must be the `data : pdfBase64` that I'm missing. Also, why doesn't it throw an error if you go onto the next line from `name : list.pdf`? I always have to put a comma if I want to do that. – Weizhong Lee Jan 26 '22 at 11:56
  • You're just copying code from someone else, hoping to answer this question without having to go into detail. – Weizhong Lee Jan 27 '22 at 02:00
  • this is worked for me! that is why I recommend you to follow this. – Khadim H. Jan 27 '22 at 05:19
  • How did you get pdfbase64? What other libraries are needed for this to work? Could you show all the code needed for this to work? – Weizhong Lee Jan 28 '22 at 07:14