2017-05-26 2 views
-1
public void sendMailWithPx() { 
    try { 
     Process p = Runtime.getRuntime().exec(new String[]{ 
       getPathSendMail(), 
       "-t" 
     }); 
     String base64File = encodeFileToBase64Binary("/Users/jacye/Downloads/test.pdf");//base64 file 
     try (OutputStreamWriter osw = new OutputStreamWriter(p.getOutputStream(), "UTF8")) { 
      osw.write("Content-Type: application/pdf\n"); 
      osw.write("From: [email protected]\n"); 
      osw.write("To: [email protected]\n"); 
      osw.write("Subject: Test send mmail\n"); 
      osw.write("CC: [email protected]\n"); 
      osw.write("BCC: [email protected]\n"); 
      osw.write("Content-Disposition: attachment; filename=test.pdf"); 
      osw.write("\n"); 
      osw.write("Content-Transfer-Encoding: base64"); 
      osw.write("\n"); 
      osw.write(base64File); 
      osw.write("this is body"); 
     } 
     p.waitFor(); 
    } catch (IOException | InterruptedException e) { 
     log.error(null, e); 
    } 
} 

private String getPathSendMail() throws IOException { 
    Properties prop = new Properties(); 
    try (InputStream input = getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)) { 
     prop.load(input); 
     return prop.getProperty("sendmail.path"); 
    } 
} 

添付ファイルと本文をメールで送信しますが、受信本文はありません。SendmailはJavaコードを使用し、本文を追加できません

本文と添付ファイルをメールで送信するにはどうすればよいですか?

+1

なぜあなたはJavaMailのを使用することはありませんでしょうか?私の顧客のために –

+0

セキュリティ..私は私を助けることができます。 – Jaycey

+0

これはコマンドライン自体から機能しますか? –

答えて

1

本文と添付ファイルがあるメールを送信する必要がある場合は、MIME Messageとして送信する必要があります。 送信しているメッセージに添付ファイルがあります(PDF)。 「これは本文です」というテキストがPDFの一部として見つかることがあると思いますが、PDFビューアでは表示されないことがあります。

シンプルMIME Messageから、次のよう

になります:ジョン・ドウ
MIME-バージョン:1.0
のContent-Type:
マルチパート/混合。 boundary = "XXXXboundary text"

これはMIME形式のマルチパートメッセージです。

--XXXXboundaryテキストのContent-Type:text/plainの

が、これは本文テキスト

--XXXXboundaryテキストのContent-Typeです:text/plainの。内容 - 処分:添付; = "test.txtの"

ファイル名は、これは添付ファイルのテキスト

--XXXXboundary text--

関連する問題