运行就出下列异常:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port:
25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1227)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:32
2)
at javax.mail.Service.connect(Service.java:236)
at javax.mail.Service.connect(Service.java:137)
at javax.mail.Service.connect(Service.java:86)
at javax.mail.Transport.send0(Transport.java:150)
at javax.mail.Transport.send(Transport.java:80)
at Mail.main(Mail.java:43)
不知道是什么原因
import javax.mail.*;
import javax.swing.*;
import java.util.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.awt.*;class PopupAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String name,password;
String result = JOptionPane.showInputDialog("Enter name password");
StringTokenizer st = new StringTokenizer(result,",");
name = st.nextToken();
password = st.nextToken();
return new PasswordAuthentication(name,password);
}
}public class Mail
{
public static void main(String[] args)
{
Authenticator auth = new PopupAuthenticator();
try{
Properties props=new Properties();
props.put("mail.transport.protocol","smtp");
props.put("mail.smpt.host","smtp.yahoo.com.cn");
Session sess=Session.getDefaultInstance(props,auth); MimeMessage msg=new MimeMessage(sess); msg.setFrom(new InternetAddress("[email protected]")); msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("[email protected]",false)); msg.setSubject("THIS IS THE MAIL");
msg.setContent("herr is some content","text/plain"); Transport.send(msg);
}catch(MessagingException m)
{
m.printStackTrace();
}
}
}
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port:
25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1227)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:32
2)
at javax.mail.Service.connect(Service.java:236)
at javax.mail.Service.connect(Service.java:137)
at javax.mail.Service.connect(Service.java:86)
at javax.mail.Transport.send0(Transport.java:150)
at javax.mail.Transport.send(Transport.java:80)
at Mail.main(Mail.java:43)
不知道是什么原因
import javax.mail.*;
import javax.swing.*;
import java.util.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.awt.*;class PopupAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String name,password;
String result = JOptionPane.showInputDialog("Enter name password");
StringTokenizer st = new StringTokenizer(result,",");
name = st.nextToken();
password = st.nextToken();
return new PasswordAuthentication(name,password);
}
}public class Mail
{
public static void main(String[] args)
{
Authenticator auth = new PopupAuthenticator();
try{
Properties props=new Properties();
props.put("mail.transport.protocol","smtp");
props.put("mail.smpt.host","smtp.yahoo.com.cn");
Session sess=Session.getDefaultInstance(props,auth); MimeMessage msg=new MimeMessage(sess); msg.setFrom(new InternetAddress("[email protected]")); msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("[email protected]",false)); msg.setSubject("THIS IS THE MAIL");
msg.setContent("herr is some content","text/plain"); Transport.send(msg);
}catch(MessagingException m)
{
m.printStackTrace();
}
}
}
解决方案 »
- 求过来人推荐一个你们认为比较好的java培训机构,打广告,网络猎手等滚粗
- 关于字符串转换Date类型
- 请问Java中线程的yield()方法,sleep()方法,wait()方法,start()方法的作用和区别
- java编程只能是写代码吗?
- 求助 如何编写代码,使网页调用applet时自动将焦点放在applet上
- 请问下列sql server2000的sp4(微软主叶上的)要下载哪个啊
- 新手问题~~~~~~~~~~~~~~~~~~~~~~~
- 播放音频 哪里出错了呢?
- 请教,猛人,一个java编程题
- remove "Java Applet Window" ?
- java初学者,推荐一些经典书和网站,谢谢!!
- 请帮我看一段JAVABEAN代码好吗?我改不出来。。谢谢。
这么浅显的英语,你看不懂么?
呵呵..如果能上网,smtp服务器直接填你的 email服务器,比如 www.163.com
否则,自己装个smtp服务器