跪求JavaMail认证方式的设置
CRAM-MD5,LOGIN,PLAIN这几个如何在JavaMail属性中设置,哪为大哥知道的告诉小弟一下,谢谢了,在线等,下面是部分代码:
public boolean sendAlertMail(AlertConfBean alertConfBean)
{
String content = createAlertMail();
smtpHost = alertConfBean.getMailServer();
receiver = alertConfBean.getMailAddress();
userID = alertConfBean.getAuthUserID();
password = alertConfBean.getAuthPassword();
subject = alertConfBean.getMailHeader();
if (!checkMailField())
{
return false;
}
Properties properties = new Properties();
properties.put( "mail.smtp.host ", smtpHost);
properties.put( "mail.smtp.auth ", "true ");
Session session = Session.getDefaultInstance(properties,
new Authenticator()
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userID, password);
}
});
MimeMessage mimeMsg = new MimeMessage(session);
try
{
mimeMsg.setFrom(new InternetAddress(sender));
mimeMsg.setRecipients(Message.RecipientType.TO, parse(receiver));
mimeMsg.setSubject(subject, "SHIFT-JIS ");
MimeBodyPart part = new MimeBodyPart();
part.setText(content == null ? " " : content, "SHIFT-JIS ");
part.setContent(content.toString(), "text/plain;charset=SHIFT-JIS ");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(part);
mimeMsg.setContent(multipart);
mimeMsg.setSentDate(new Date());
Transport.send(mimeMsg);
return true;
} catch (
MessagingException exception)
{
m_log.error( "MessageException ", exception);
return false;
}
}
------解决方案--------------------public boolean connect() throws MessagingException,
IOException {
if (isConnected())
return true;
// ユーザはメール設定がなければ、接続を諦める
if (!validation)
return false;
// ユーザはメール設定がなければ、接続を諦める
if (receiveHost == null)
return false;
if (receiveHost.length() == 0)
return false;
if (sendHost == null)
return false;
if (sendHost.length() == 0)
return false;
URLName url;
if (protocol.equalsIgnoreCase(PROTOCOL_IMAP4)) {
url = new URLName(protocol, receiveHost, -1, INBOX_FOLDERNAME, logonName,
logonPassword);
cat.debug( "Connect URL: " + protocol + ":// " + logonName + ":xxxxx@ "
+ receiveHost + "/ " + INBOX_FOLDERNAME);
} else {
String mboxdir = PropMngr.getTempDirPath();
// String mboxdir = PropMngr.getProperty( "MailDir ");
cat.debug( "MailBoxTempDir= " + mboxdir);
if (mboxdir == null) {
throw new MessagingException(