javamial问题,很简单的,熟悉javamail请进 用javamail做邮件发送程序,我用的sina邮箱作为邮件服务器,发送邮件有时成功有时失败`` 这是我代码的问题`还是这样发邮件本身就只有一定成功率? 有人说是邮件服务器的问题,我用的是普通注册邮箱,如果换上公司邮箱会不会好点? 平时大家是用什么邮件服务器的? 如果大家认为是代码问题我再把代码发上来··应为我感觉代码好像没什么问题··o(∩_∩)o... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有可能是sina的服务器问题,如果公司有自己的emailServer,smtpHost 那就用公司的啊!我就用的是公司的...不会有你的问题 >_<不过还是想看一下你的代码... try{ //从html表单中获取邮件信息 String tto=sendMeailForm.getTo(); String ttitle=sendMeailForm.getTitle(); String tcontent=sendMeailForm.getContent(); System.out.println(tto+"///"+ttitle+"///"+tcontent); Properties props=new Properties props.put("mail.smtp.host","smtp.sina.com");//存储发送邮件服务器的信息 props.put("mail.smtp.auth","true");//同时通过验证 Session s=Session.getInstance(props);//根据属性新建一个邮件会话 s.setDebug(true); MimeMessage message=new MimeMessage(s);//由邮件会话新建一个消息对象 //设置邮件 InternetAddress from=new InternetAddress("[email protected]"); message.setFrom(from);//设置发件人 InternetAddress to=new InternetAddress(tto); message.setRecipient(Message.RecipientType.TO,to);//设置收件人,并设置其接收类型为TO message.setSubject(ttitle);//设置主题 message.setText(tcontent);//设置信件内容 message.setSentDate(new Date());//设置发信时间 //发送邮件 message.saveChanges();//存储邮件信息 Transport transport=s.getTransport("smtp"); transport.connect("smtp.sina.com","huacan_fly","lxf2628");//以smtp方式登录邮箱 transport.sendMessage(message,message.getAllRecipients());//发送邮件,其中第二个参数是所有 //已设好的收件人地址 transport.close(); }catch(MessagingException e){ System.out.println(e.toString()); } 给你个邮件安全认证方法试试public static class PopupAuthenticator extends Authenticator { String username = null; String password = null; public PopupAuthenticator() { } public PasswordAuthentication performCheck(String user, String pass) { username = user; password = pass; return getPasswordAuthentication(); } protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }然后调用方法PopupAuthenticator popA = new PopupAuthenticator();// 邮件安全认证。 PasswordAuthentication pop = popA.performCheck(username, password); // 填写用户名及密码 session = Session.getInstance(properties, popA); 指定目录下创建文件时的路径问题? LSTL如何倒序遍历 请教函数的string参数 如何制作类似struts中html:text标签,我想制作一个特定样式的html:text 从mysql数据库中读取比较大的图片,在jsp页面中就不能显示,感觉是I/O流写的不合适,谁来帮帮我呀 freemarker 在指令里可以放集合的变量名吗? eclipse为什么总是这样 急,在线候 read數據錯誤,請幫忙 我想在PC上搭一个学JSP,SERVLETS的学习环境!我要装些什么啊? 如何做到敲回车即可登陆,而不用点击按钮 (ExtJs) 一个奇怪的问题,希望牛人能解决。加急!!!
如果公司有自己的emailServer,smtpHost 那就用公司的啊!
我就用的是公司的...不会有你的问题 >_<
不过还是想看一下你的代码...
//从html表单中获取邮件信息
String tto=sendMeailForm.getTo();
String ttitle=sendMeailForm.getTitle();
String tcontent=sendMeailForm.getContent();
System.out.println(tto+"///"+ttitle+"///"+tcontent);
Properties props=new Properties
props.put("mail.smtp.host","smtp.sina.com");//存储发送邮件服务器的信息
props.put("mail.smtp.auth","true");//同时通过验证
Session s=Session.getInstance(props);//根据属性新建一个邮件会话
s.setDebug(true); MimeMessage message=new MimeMessage(s);//由邮件会话新建一个消息对象 //设置邮件
InternetAddress from=new InternetAddress("[email protected]");
message.setFrom(from);//设置发件人
InternetAddress to=new InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO,to);//设置收件人,并设置其接收类型为TO
message.setSubject(ttitle);//设置主题
message.setText(tcontent);//设置信件内容
message.setSentDate(new Date());//设置发信时间 //发送邮件
message.saveChanges();//存储邮件信息
Transport transport=s.getTransport("smtp");
transport.connect("smtp.sina.com","huacan_fly","lxf2628");//以smtp方式登录邮箱
transport.sendMessage(message,message.getAllRecipients());//发送邮件,其中第二个参数是所有
//已设好的收件人地址
transport.close();
}catch(MessagingException e){
System.out.println(e.toString());
}
public static class PopupAuthenticator extends Authenticator { String username = null; String password = null; public PopupAuthenticator() {
} public PasswordAuthentication performCheck(String user, String pass) {
username = user;
password = pass;
return getPasswordAuthentication();
} protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
}然后调用方法
PopupAuthenticator popA = new PopupAuthenticator();// 邮件安全认证。
PasswordAuthentication pop = popA.performCheck(username, password); // 填写用户名及密码
session = Session.getInstance(properties, popA);