日期:2014-05-18  浏览次数:20575 次

谁帮我解决下JavaMail的问题,求了,问了几次没人回
请问CRAM-MD5,LOGIN,PLAIN这几个如何在JavaMail属性中设置??
mail.smtp.saslrealm这个吗??请知道的速回,谢谢了,最好有代码,直接贴在下面,谢谢拉


------解决方案--------------------
package com.j2ee14.ch6;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
import javax.activation.*;
public class SendAttachment extends MailProcessBase
{
String from= "hellking@127.0.0.1 ";
String to= "hellking2@127.0.0.1 ";
String filename= "SendAttachment.java ";
public SendAttachment()throws Exception
{
super();
}
public void sendAttachment()
{
try
{
// 创建消息,并设置收件人、发件人和消息主体
Message message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject( "带有附件的消息 ");
// 创建并填充消息的第一部分
BodyPart mbp = new MimeBodyPart();
mbp.setText( "hello,hellking! ");
// 创建Multipart容器,并将消息的第一部分加入容器中
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mbp);
// 创建并使用文件数据源填充消息的第二部分,同时保留附件的原始文件名
BodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
// 将消息的第二部分即附件加入容器中
multipart.addBodyPart(messageBodyPart);
// 将Multipart对象设置为消息内容
message.setContent(multipart);
// 发送消息
Transport.send(message);
}

catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)throws Exception
{
new SendAttachment().sendAttachment();

}

}

------解决方案--------------------
mail.jspgen.com