DEBUG: setDebug: JavaMail version 1.3
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s
mtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG: SMTPTransport trying to connect to host "127.0.0.1", port 25
DEBUG SMTP RCVD: 220 acumen-2e4f399a4 Microsoft ESMTP MAIL Service, Version: 5.0.
2195.5329 ready at Fri, 2 Apr 2004 22:49:05 +0800
DEBUG: SMTPTransport connected to host "127.0.0.1", port: 25
DEBUG SMTP SENT: EHLO acumen-2e4f399a4
DEBUG SMTP RCVD: 250-acumen-2e4f399a4 Hello [127.0.0.1]
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-SIZE 2097152
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250 OK
DEBUG SMTP Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP Found extension "SIZE", arg "2097152"
DEBUG SMTP Found extension "PIPELINING", arg ""
DEBUG SMTP Found extension "DSN", arg ""
DEBUG SMTP Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP Found extension "8bitmime", arg ""
DEBUG SMTP Found extension "BINARYMIME", arg ""
DEBUG SMTP Found extension "CHUNKING", arg ""
DEBUG SMTP Found extension "VRFY", arg ""
DEBUG SMTP Found extension "OK", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP SENT: AUTH LOGIN
DEBUG SMTP RCVD: 334 VXNlcm5hbWU6
DEBUG SMTP SENT:
DEBUG SMTP RCVD: 501 5.7.3 Cannot decode arguments //???????
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:264)
at javax.mail.Service.connect(Service.java:134)
at sendMail.sendMessage(sendMail.java:59)
at sendMail.main(sendMail.java:74)
sendMessage.returninfo false
Press any key to continue...
代码如下:
import java.util.* ;
import java.io.* ;
import javax.mail.* ;
import javax.mail.internet.* ;
import javax.activation.* ;
import java.sql.*;
public class sendMail{
public String sendMessage(String smpthost,String sendto,String sendfromaddress,String username,String passwd,String
OrderDateInfo,String UserIDInfo,String OrderIDInfo)
{
String returninfo="true";
try{
String title="谢谢使用宠物网络商店";
Properties props = System.getProperties();
props.put("mail.smtp.host",smpthost);//存储发送邮件服务器的信息
props.put("mail.smtp.auth","true");//同时通过验证
Session s=Session.getInstance(props);//根据属性新建一个邮件会话
s.setDebug(true);
MimeMessage message=new MimeMessage(s);//由邮件会话新建一个消息对象
//设置邮件
InternetAddress sendfrom=new InternetAddress(sendfromaddress);
message.setFrom(sendfrom);//设置发件人
InternetAddress to=new InternetAddress(sendto);
message.setRecipient(Message.RecipientType.TO,to);//设置收件人,并设置其接收类型为TO
message.setSubject(title);//设置主题
message.setSentDate(new java.util.Date());//设置发信时间
BodyPart messageBodyPart = new MimeBodyPart();
StringBuffer br=new StringBuffer();
br.append("<html>");
br.append("<head>");
br.append("<title>宠物网络商店</title>");
br.append("</head>");
br.append("<body>");
br.append("<br> 客户: "+UserIDInfo+", 您好!");
br.append("<p> 订单号码:"+OrderIDInfo+"</p>");
br.append("<p> 订购日期:"+OrderDateInfo+"</p>");
br.append("</body>");
br.append("</html>");
String htmlText =br.toString();
messageBodyPart.setContent(htmlText,"text/html; charset=GB2312");
MimeMultipart multipart = new MimeMultipart("related");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
//发送邮件
message.saveChanges();
Transport transport=s.getTransport("smtp");
transport.connect(smpthost,username,passwd);//******//
transport.sendMessage(message,message.getAllRecipients());
transport.close();
}catch(MessagingException e){
e.printStackTrace();
returninfo="false";
}
System.out.println("sendMessage.returninfo "+returninfo);
return returninfo;
}
public static void main(String args[]){
new sendMail().sendMessage("127.0.0.1","acumen@163.com","acumen@163.com","","12345678","2004-4-2","acumen","11");
}
}
5 个解决方案
#1
学习ing
#2
客人少:(
#3
有高手吗
#4
up
#5
new sendMail().sendMessag("127.0.0.1","acumen@163.com","acumen@163.com","","12345678","2004-4-2","acumen","11");
把"127.0.0.1"改为"smtp.163.com"
把"127.0.0.1"改为"smtp.163.com"
#1
学习ing
#2
客人少:(
#3
有高手吗
#4
up
#5
new sendMail().sendMessag("127.0.0.1","acumen@163.com","acumen@163.com","","12345678","2004-4-2","acumen","11");
把"127.0.0.1"改为"smtp.163.com"
把"127.0.0.1"改为"smtp.163.com"