帮我看看这段程序,我弄了很久都找不出问题出在哪? 程序可以运行但是不能把邮件发到我的邮箱 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你个源码,在我这里已经成功了的import java.io.*;import java.util.*;import java.util.Date;import javax.activation.DataHandler;import javax.mail.*;import javax.mail.internet.*;import javax.swing.JOptionPane;public class Mail{ String myEmail="*****"; public boolean sendMail(String subject,String body,String to) { try { SmtpAuth sa=new SmtpAuth(); // 密码验证 sa.getuserinfo(user,pass); Properties props=System.getProperties(); props.put("mail.smtp.auth","true"); props.put("mail.smtp.host","smtp.sina.com.cn"); Session sess=Session.getInstance(props,sa); Message msg = new MimeMessage(sess); msg.setDataHandler(new DataHandler(body,"text/html; charset=gb2312")); msg.setFrom(new InternetAddress(myEmail,user)); msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false)); msg.setSubject(subject); msg.setSentDate(new Date()); msg.setText(body); Transport.send(msg); JOptionPane.showMessageDialog(null,"发送成功","成功",JOptionPane.OK_OPTION); return true; } catch (Exception e) { return false; } } public static void main(String[] args){ Mail m=new Mail(); m.sendMail("测试","test javamail api",myEmail); System.exit(0); }}class SmtpAuth extends javax.mail.Authenticator{ //SMTP身份验证 private String user,password; public void getuserinfo(String getuser,String getpassword){ user=getuser; password=getpassword; } protected javax.mail.PasswordAuthentication getPasswordAuthentication(){ return new javax.mail.PasswordAuthentication(user,password); }} 求解问题! 一段Swing程序无法实现触发按钮事件 为什么添加了图片以后整个类保存错误 !!跪求答案 如何解决jarEntry中出现乱码的情况 一个JAVA2来实现ComboBox的问题!! 如何才能做到不被别人复制页面中的内容和查看源代码?? java如何把汉字转成象%BA%BA的编码? 谁知道在哪里能下到SWING包吗,还是一定要用SWING这个软件啊!!! tomc启动服务报错,急急!!1 JAVA文件数据对比怎么差距巨大? 初学者请教 这是为什么???!!!!!
import java.io.*;
import java.util.*;
import java.util.Date;
import javax.activation.DataHandler;
import javax.mail.*;
import javax.mail.internet.*;
import javax.swing.JOptionPane;public class Mail
{
String myEmail="*****";
public boolean sendMail(String subject,String body,String to)
{
try
{
SmtpAuth sa=new SmtpAuth(); // 密码验证
sa.getuserinfo(user,pass);
Properties props=System.getProperties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host","smtp.sina.com.cn");
Session sess=Session.getInstance(props,sa); Message msg = new MimeMessage(sess);
msg.setDataHandler(new DataHandler(body,"text/html; charset=gb2312")); msg.setFrom(new InternetAddress(myEmail,user));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(body);
Transport.send(msg);
JOptionPane.showMessageDialog(null,"发送成功","成功",JOptionPane.OK_OPTION);
return true;
}
catch (Exception e)
{
return false;
}
} public static void main(String[] args){
Mail m=new Mail();
m.sendMail("测试","test javamail api",myEmail);
System.exit(0);
}
}
class SmtpAuth extends javax.mail.Authenticator{ //SMTP身份验证
private String user,password;
public void getuserinfo(String getuser,String getpassword){
user=getuser;
password=getpassword;
} protected javax.mail.PasswordAuthentication getPasswordAuthentication(){
return new javax.mail.PasswordAuthentication(user,password);
}
}