当前位置: 技术问答>java相关
(重发)请大虾们百忙之中帮看一下这段代码哪里有问题?
来源: 互联网 发布时间:2015-09-06
本文导语: 请问我的mail测试程序为什么老说地址解析不对, 用的服务器都能telnet xxx 25到啊 感谢! package myjava; import myjava.*; import javax.swing.UIManager; public class main { ...
请问我的mail测试程序为什么老说地址解析不对,
用的服务器都能telnet xxx 25到啊
感谢!
package myjava;
import myjava.*;
import javax.swing.UIManager;
public class main {
public static void main(String[] args) {
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
System.out.println(e);
}
myFrame fr=new myFrame();
fr.setSize(400,400);
fr.setLocation(250,100);
fr.setTitle("发信");
fr.setVisible(true);
}
}
package myjava;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import javax.mail.internet.*;
import javax.mail.*;
import javax.swing.UIManager;
import java.util.*;
import java.awt.event.*;
class myFrame extends JFrame {
GridBagConstraints gbc;
Container context;
JButton bt;
JTextField Address;
public myFrame() {
init();
}
public void sendMail(String toAddr, String subject, String body, String fromAddr)
{
try
{
gbc.gridy=3;
Properties props = new Properties();
props.put("public.km.yn.cn","public.km.yn.cn");
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddr));
InternetAddress[] tos =InternetAddress.parse(toAddr);
msg.setRecipients(Message.RecipientType.TO,tos);
msg.setSubject(subject);
msg.setText(body);
Transport.send(msg);
JOptionPane.showMessageDialog(null,"成功发出!");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
public void init()
{
gbc=new GridBagConstraints();
bt=new JButton("发信");
Address=new JTextField("eerie@email.com");
context=getContentPane();
context.setLayout(new GridBagLayout());
gbc.gridy=0;
gbc.gridx=0;
context.add(Address,gbc);
gbc.gridy=10;
context.add(bt,gbc);
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
gbc.gridy=1;
JLabel Msg=new JLabel("发信中....");
context.add(Msg,gbc);
sendMail(Address.getText(),"test","try","eerie@email.com");
}
});
}
}
用的服务器都能telnet xxx 25到啊
感谢!
package myjava;
import myjava.*;
import javax.swing.UIManager;
public class main {
public static void main(String[] args) {
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
System.out.println(e);
}
myFrame fr=new myFrame();
fr.setSize(400,400);
fr.setLocation(250,100);
fr.setTitle("发信");
fr.setVisible(true);
}
}
package myjava;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import javax.mail.internet.*;
import javax.mail.*;
import javax.swing.UIManager;
import java.util.*;
import java.awt.event.*;
class myFrame extends JFrame {
GridBagConstraints gbc;
Container context;
JButton bt;
JTextField Address;
public myFrame() {
init();
}
public void sendMail(String toAddr, String subject, String body, String fromAddr)
{
try
{
gbc.gridy=3;
Properties props = new Properties();
props.put("public.km.yn.cn","public.km.yn.cn");
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddr));
InternetAddress[] tos =InternetAddress.parse(toAddr);
msg.setRecipients(Message.RecipientType.TO,tos);
msg.setSubject(subject);
msg.setText(body);
Transport.send(msg);
JOptionPane.showMessageDialog(null,"成功发出!");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
public void init()
{
gbc=new GridBagConstraints();
bt=new JButton("发信");
Address=new JTextField("eerie@email.com");
context=getContentPane();
context.setLayout(new GridBagLayout());
gbc.gridy=0;
gbc.gridx=0;
context.add(Address,gbc);
gbc.gridy=10;
context.add(bt,gbc);
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
gbc.gridy=1;
JLabel Msg=new JLabel("发信中....");
context.add(Msg,gbc);
sendMail(Address.getText(),"test","try","eerie@email.com");
}
});
}
}
|
props.put("public.km.yn.cn","public.km.yn.cn"); ??