java mail问题,请大家帮忙解决!

limingxi007 2004-07-15 08:29:21
package javamail;

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;

public class SendJavaMail{

public static void main(String[] args){

try{
Properties mailProps=new Properties();
mailProps.put("mail.smpt.host","smtp.tom.com");

Session mailSession=Session.getDefaultInstance(mailProps);

Transport transport=mailSession.getTransport("smtp");//创建Transport,使用smtp协议

MimeMessage message=new MimeMessage(mailSession);

InternetAddress fromAdd=new InternetAddress("limingxi697@tom.com");
InternetAddress r[] = new InternetAddress[1];
//System.out.println(fromAdd.getAddress());
message.setFrom(fromAdd);
r[0] = fromAdd;
InternetAddress[] toAdd =InternetAddress.parse("limingxi697@tom.com");
message.setRecipients(Message.RecipientType.TO,toAdd);
message.setSubject("Hello from Java Mail!");
message.setText("Hello!\n"+"It is I,Senor Coffee Bean!I bring you greetings. \n"
+ " from the java mail API! . \n"+
" Senor Coffee Bean,Esp.\n");
message.saveChanges();
transport.connect("smtp.tom.com","******","******");
System.out.println("====connected!====");
transport.send(message);
transport.close();
}catch(Exception exc){
System.out.println(exc.getMessage());
exc.printStackTrace();
}

}
}
这是源代码,运行时send()方法一直报错,请各位帮忙解决!
...全文
158 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
朋友别哭 2004-07-18
  • 打赏
  • 举报
回复
up一下
nelson1983 2004-07-18
  • 打赏
  • 举报
回复
认证问题,你需要一个传密码认证的类
需要认证的邮件这句话是不够的:transport.connect("smtp.tom.com","******","******");
认证的类是继承自javax,mail包中的一个类,类名我忘了,你自己搜索一下,满街都是!
limingxi007 2004-07-18
  • 打赏
  • 举报
回复
up一下,有谁能解答!
xxy802 2004-07-15
  • 打赏
  • 举报
回复
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class B2BMail {
public void SendMail( String strMailFrom, String strMailTo, String strMailSubject,
String strMailBody, String strMailErrorsTo
) throws B2BBusinessException {

String host_name = "";
try {
host_name = InetAddress.getLocalHost().getHostAddress();
} catch( UnknownHostException e ) {
throw new B2BBusinessException( B2BMessage.getMessage(2018) );
}

Properties props = System.getProperties();
props.put( "mail.smtp.host", host_name );
props.put( "mail.smtp.from", strMailErrorsTo );

Session session = Session.getDefaultInstance( props, null );
try{
MimeMessage msg = new MimeMessage(session);
InternetAddress from_adr = new InternetAddress( strMailFrom );
msg.setFrom( from_adr );
InternetAddress to_adr[] = InternetAddress.parse( strMailTo );
msg.setRecipients( Message.RecipientType.TO, to_adr );
msg.setSubject( strMailSubject, "iso-2022-jp" );
msg.setSentDate( new Date() );
msg.setText( strMailBody, "iso-2022-jp" );


Transport.send( msg );
}catch ( MessagingException e ) {
throw new B2BBusinessException( B2BMessage.getMessage(2017) + e.getMessage() );
}catch ( Exception e ) {
throw new B2BBusinessException( B2BMessage.getMessage(2017) + e.getMessage() );
}
}
}
limingxi007 2004-07-15
  • 打赏
  • 举报
回复
这是返回的异常信息:
Sending failed;
nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class javax.mail.SendFailedException: 550 5.7.1 Unable to relay for limi
ngxi697@tom.com

javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class javax.mail.SendFailedException: 550 5.7.1 Unable to relay for limi
ngxi697@tom.com

at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at javamail.SendJavaMail.main(SendJavaMail.java:36)
Press any key to continue...

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧