2012-04-02 15 views
0

Google CSPの添付ファイルを使用してメールを送信しようとしています。受信者がメールを受信しませんでした。 Google App Engineでログを確認したところ、エラーは報告されませんでした。何がうまくいかないでしょうか?誰かがGoogアプリケーションエンジンを使用して添付ファイルとしてメールでCSVファイルを送信できるかどうか教えてください。はいの場合は、どうすればいいか教えてください。CSVファイルを添付したGmailメールをGoogleのアプリケーションエンジンに送信する方法

 Properties props = new Properties(); 
Session session = Session.getDefaultInstance(props, null); 

try { 
    Message msg = new MimeMessage(session); 
    msg.setFrom(new InternetAddress("[email protected]"," Admin")); 
     msg.addRecipient(Message.RecipientType.TO, new InternetAddress(emailto, "Mr. User")); 
    msg.setSubject("Expence Tracker with Attachment"); 

    String htmlBody=msgbody; 

    byte[] attachmentData= attach.getBytes(); 
     Multipart mp = new MimeMultipart(); 

    MimeBodyPart htmlPart = new MimeBodyPart(); 
    htmlPart.setContent(htmlBody, "text/html"); 
    mp.addBodyPart(htmlPart); 

    MimeBodyPart attachment = new MimeBodyPart(); 
    attachment.setFileName("myfile.csv"); 
    attachment.setContent(attachmentData, "text/comma-separated-values"); 
    mp.addBodyPart(attachment); 

    msg.setContent(mp); 

    //resp.getWriter().println("Mail Details :To- "+emailto); 

} catch (AddressException e) { 

    resp.getWriter().println("Mail Details :Error "+e); 
} catch (MessagingException e) { 
    resp.getWriter().println("Mail Details :Error "+e); 
} 
+1

あなたが作成したメッセージを送信する方法はありません。コードの別の部分にありますか?もしそうなら、それを共有することはできますか? – Justmaker

答えて

0

これはCSV添付ファイルの送信例です。 CSVはブロブストアにあります。 GAE Mailとblobstore APIを使用するのはPythonです。これをJavaに翻訳することは難しくありません。

blob_key = files.blobstore.get_blob_key(file_name) 
    blob_info = blobstore.BlobInfo.get(blob_key)   
    blob_reader = blobstore.BlobReader(blob_key)       
    message = mail.EmailMessage(sender = '[email protected], 
           subject = 'CSV attached')   
    message.body = 'Download attached CSV'      # only a text body 
    message.attachments = [blob_info.filename,blob_reader.read()] 
    message.send() 
関連する問題