Google app engine 未在gae上使用Java Mail API加载附件pdf

Google app engine 未在gae上使用Java Mail API加载附件pdf,google-app-engine,pdf,jakarta-mail,Google App Engine,Pdf,Jakarta Mail,此代码用于向电子邮件动态发送pdf附件。 此代码将部署在google app engine上。 代码正常,没有例外,收到电子邮件,但无法加载pdf附件 public class EmalTableServlet extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws IOException { res.set

此代码用于向电子邮件动态发送pdf附件。 此代码将部署在google app engine上。 代码正常,没有例外,收到电子邮件,但无法加载pdf附件

public class EmalTableServlet extends HttpServlet {

    public void service(HttpServletRequest req, HttpServletResponse res)
            throws IOException {
        res.setContentType("text/plain");
        PrintWriter out = res.getWriter();

        String sub = "You requested an Article";
        String to = "*********@gmail.com";
        String body = "hello";
        try {
            // String message = req.getParameter("data");

            email cs = new email(to, sub, body);
            cs.send();

            out.write("Email Sent Successfully");
        }
        catch(Exception e) {
            System.out.println(e);
        }
    }

}

请看。@Unihedron请调试代码或告诉我错误加载失败是什么意思?您是否已获取附件并将其保存在文件中,但无法使用pdf查看器显示它?@BillShannon我将该文件作为附件与.pdf一起获取,但pdf可以加载它保存附件并将该文件与您发送的文件进行比较。它们大小一样吗?相同的内容?
class email {
    String toAddress;
    String owner = "*****@gmail.com";
    String sub;
    String msg;

    email() {}

    public email(String email, String sub, String msg) {
        super();
        this.toAddress = email;
        this.sub = sub;
        this.msg = msg;
    }

    void send() {

        String htmlbody = "<table style=\"width:300px\"><tr>  <td>Jill</td>  <td>Smith</td>  <td>50</td></tr><tr>  <td>Eve</td>  <td>Jackson</td>  <td>94</td></tr></table><br><br><a href=\"www.thotopic.appspot.com\">link</a>";  
        Properties p = new Properties();
        Session s = Session.getDefaultInstance(p, null);
        Multipart mp = new MimeMultipart();
        MimeBodyPart htmlpart = new MimeBodyPart();
        System.out.println("<-------------------------------Mail Sent------------------------->" + toAddress);
        try {
            htmlpart.setContent(htmlbody, "text/html");
            mp.addBodyPart(htmlpart);
            Message mess = new MimeMessage(s);
            mess.setFrom(new InternetAddress(owner, "Example.com Admin"));
            InternetAddress to = new InternetAddress(toAddress);
            mess.addRecipient(Message.RecipientType.TO, to);
            mess.setSubject(sub);
            mess.setContent(mp);

            Multipart mp1 = new MimeMultipart();

            String example = "Convert Java String";
            byte[] pdf1 = example.getBytes();
            // Attaching first pdf
            MimeBodyPart attachment = new MimeBodyPart();
            attachment.setFileName("pdf1.pdf");
            DataSource src = new ByteArrayDataSource(pdf1, "application/pdf"); 
            attachment.setDataHandler(new DataHandler(src));
            mp1.addBodyPart(attachment);
            mess.setContent(mp1);
            Transport.send(mess);

        }
        catch (Exception e) {
            System.out.println(e);
        }
    }

}