我发送附件邮件......
此源代码正在从html解析为html,并且运行良好:
SmtpClient sm = new SmtpClient(selSMTPServer(from));
sm.from(from_mail);
sm.to(to);
PrintStream msg = sm.startMessage();
//Base64Encoder b64e = new Base64Encoder(msg);
BASE64EncoderStream b64e = new BASE64EncoderStream(msg);
//org.jboss.security.Base64Encoder b64e = new Base64Encoder();
msg.print("From: ");
msg.println(from_name+"<"+from_mail+">");
msg.print("To: ");
msg.println(to_name+"<"+to+">");
msg.print("Subject: ");
msg.println(subject);
msg.println("MIME-Version: 1.0");
msg.println("Content-Type: multipart/mixed;");
msg.println("\tboundary=\"----=_next_part\"");
msg.println("\r");
msg.println("This is a multipart message in MIME format.");
msg.println("\r");
msg.println("------=_next_part");
msg.println("Content-Type:text/html; charset=\"euc-kr\"");
msg.println("Content-Transfer-Encoding: 8bit");
msg.println("\r");
msg.println(body);
msg.println("\r");
int fileNameLength = fileName.length;
for (int k=1;k < fileNameLength; k++){
if (!fileName[k].equals(""))
{
/* attachment file */
if (k >1)
{
msg.println("\r\n");
}
msg.println("------=_next_part");
msg.println("Content-Type: application/octet-stream;");
msg.println("\tname=\""+fileName[k]+"\"");
msg.println("Content-Transfer-Encoding: base64");
msg.println("Content-Disposition: attachment;");
msg.println("\tfilename=\""+fileName[k]+"\"");
msg.println("\r\n");
File f = new File(filePath+fileName[k]);
FileInputStream fis = new FileInputStream(f);
int n = 0;
do{
byte[] fcontent = {0, 0, 0};
n = fis.read(fcontent, 0, 3);
if (n != -1){
b64e.write(fcontent);
}
}while(n != -1);
fis.close();
fis = null;
f = null;
但创建的文件已减少......
离)
创建文件
<div class="col-md-6 text-right" style="padding-top:30px;"> <p class="exhibition-info">Tel. <span class="exhibition-tel">111-111-111</span> / Fax. <span class="exhibition-fax"></span></p> <p class="dealer-info"><span class="dealer-hp">111-111-111</span> / <span class="dealer-mail">kwang@dongsung.com</span></p> </div> <div cl
原始资料
<div class="col-md-6 text-right" style="padding-top:30px;"> <p class="exhibition-info">Tel. <span class="exhibition-tel">111-111-111</span> / Fax. <span class="exhibition-fax"></span></p> <p class="dealer-info"><span class="dealer-hp">111-111-111</span> / <span class="dealer-mail">kwang@dongsung.com</span></p> </div> <div class="col-md-12" style="padding-top:30px;">
为什么会出现这些问题?
答案 0 :(得分:0)
我已经解决了这个问题 工作得很好。
do{
byte[] data = byte[1024];
n = fis.read(data, 0, data.length);
if (n != -1)
{
b64e.write(data);
}
}while(n != -1);