GWT で添付ファイル付きのメールを送信する方法があれば教えてください。添付ファイルなしで簡単なメールを送信することはできましたが、ファイルを追加しようとすると問題が発生します。
問題は、「FileUpload」がファイルのフルパスを提供しないことです
安全上の理由から、クライアントからファイルのフル パスを取得することはできないようです。論理サーバーを gwt クライアントに保持する別の方法はありますか?
私のコード
クライアント側:
FileUpload upload = new FileUpload();
// cannot retrieve the full path
String fileAttachment = upload.getName();
サーバ側:
public void sendMail(String sender, String[] recipients, String subject, String message, String fileAttachment) {
try {
...(init)
// Part two is attachment
messageBodyPart = new MimeBodyPart();
// => fileAttachment need full path
DataSource source =
new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(
new DataHandler(source));
messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
msg.setContent(multipart);
// Send
Transport.send(msg);
}
ご協力いただきありがとうございます