java代码发邮件和附件 java发送邮件附件( 三 )


sendmail attachfile( d:\\news rar );
sendmail attachfile( d:\\jhjl rar );
System out println(sendmail sendMail());
}
lishixinzhi/Article/program/Java/hx/201311/25753
如何将java在DOMINO中发送的邮件带上附件我们要用DOMINO5R的例子重写一下:
rti.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null,
attachFilePath, attachFilePath); // 添加附件
注:其中rti = (RichTextItem) memo.createRichTextItem("Body");
让邮件带上附件就一句话,很简单吧 。
如果,你不明白其中的参数 , 还是会搞不出来 , 一个字晕!
其中前两个参数我就不说了,第三个和第四个参数写成一样就可以了 。
强烈注意:
1* 添加的附件必须放在DOMINO服务器上,不能放在客户端添加附件 , 不要问为什么,这是事实 。你在客户端的硬盘上无论放在哪,它也不让你上传 。
2*我们的项目环境,DOMINO是运行在AS400上,它的安装目录是em_01,我们就假设把附件放在AS400 的em_01/test/test.tar,在程序使用相对路径,"test/test.tar"相对于邮件的根目录em_01.
如果,按我说的做法应该不会有问题了 。若想看一个完整例子 , 请参考我的“java在收 。发lotus邮件的实例了” 。
怎么用java发送带附件的邮件代码详解package email;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import sun.misc.BASE64Encoder;
public class Mail {
private static final String LINE_END = "\r\n";
private boolean isDebug = true;
private boolean isAllowReadSocketInfo = true;
private String host;
private String from;
private ListString to;
private ListString cc;
private ListString bcc;
private String subject;
private String user;
private String password;
private String contentType;
private String boundary;
private String boundaryNextPart;
private String contentTransferEncoding;
private String charset;
private String contentDisposition;
private String content;
private String simpleDatePattern;
private String defaultAttachmentContentType;
private ListMailPart partSet;
private static MapString, String contentTypeMap;
static {
// MIME Media Types
contentTypeMap = new HashMapString, String();
contentTypeMap.put("xls", "application/vnd.ms-excel");
contentTypeMap.put("xlsx", "application/vnd.ms-excel");
contentTypeMap.put("xlsm", "application/vnd.ms-excel");
contentTypeMap.put("xlsb", "application/vnd.ms-excel");
contentTypeMap.put("doc", "application/msword");
contentTypeMap.put("dot", "application/msword");
contentTypeMap.put("docx", "application/msword");
contentTypeMap.put("docm", "application/msword");
contentTypeMap.put("dotm", "application/msword");
}
private class MailPart extends Mail {
public MailPart() {
}
}
public Mail() {
defaultAttachmentContentType = "application/octet-stream";
simpleDatePattern = "yyyy-MM-dd HH:mm:ss";
boundary = "--=_NextPart_zlz_3907_" + System.currentTimeMillis();
boundaryNextPart = "--" + boundary;
contentTransferEncoding = "base64";
contentType = "multipart/alternative";
charset = Charset.defaultCharset().name();

推荐阅读