javamail发邮件如何实现不用用户名和密码 javamail发邮件如何实现不用用户名和密码请各位高手给个源码看看 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Properties props = new Properties();props.put("mail.smtp.auth","false");设置成false就不需要认证了,网上很多例子的,google一下,呵呵 哦,好的,。我的邮箱是 [email protected] 谢谢啊 /* * 用你自己的mailserver啊,在配置文件中写好 * 用户名、密码、邮件服务器,程序中读取出来 * 然后调用sendAttach方法就行啦。 */ private static String host = Properties.getSystemProperty("mail.server"); private static String user = Properties.getSystemProperty("mail.server.user"); private static String password = Properties.getSystemProperty("mail.server.password");/** * @from:发件人 * @to: 收件人 * @subject:邮件标题 * @subject:邮件内容 * @fileName:附件 */ public static void sendAttach(String from, String to, String subject, String content, String fileName) { Properties props = new Properties(); props.put("mail.smtp.host", host); props.put("mail.smtp.auth", "true"); if (from == null || from.trim().length() == 0) { from = systemEmail; } try { Session mailSession = Session.getDefaultInstance(props); mailSession.setDebug(true); Message message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(content, "text/html;charset=GB2312"); // attached Date now = new Date(); long name = now.getTime(); BodyPart messageBodyPart2 = new MimeBodyPart(); messageBodyPart2.setFileName(name + ""); FileDataSource fileDataSource = new FileDataSource(fileName); messageBodyPart2.setDataHandler(new DataHandler(fileDataSource)); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); multipart.addBodyPart(messageBodyPart2); message.setContent(multipart); message.saveChanges(); Transport transport = mailSession.getTransport("smtp"); transport.connect(host, user, password); transport.sendMessage(message, message.getAllRecipients()); transport.close(); } catch (Exception e) { System.out.println(e); } }***************************************************************做个广告^_^:欢迎加入我刚建立的群组:http://group.csdn.net/qwert*************************************************************** 上面是带附件的方法,不带附件用:public static void send(String from, String to, String subject, String content) { Properties props = new Properties(); props.put("mail.smtp.host", host); props.put("mail.smtp.auth", "true"); if (from == null || from.trim().length() == 0) { from = systemEmail; } try { MailAuthenticator myauth = new MailAuthenticator(user, password); Session mailSession = Session.getInstance(props, myauth); mailSession.setDebug(true); Message message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); message.setText(content); message.saveChanges(); Transport transport = mailSession.getTransport("smtp"); transport.connect(host, user, password); transport.sendMessage(message, message.getAllRecipients()); transport.close(); } catch (Exception e) { System.out.println(e); } } jr_zhang(梅川内酷) MailAuthenticator myauth = new MailAuthenticator(user, password);这个类怎么写啊 class MailAuthenticator extends Authenticator { private String strUser; private String strPwd; public MailAuthenticator(String user, String password) { this.strUser = user; this.strPwd = password; } 这个不行的吧,SMTP协议现在规定没有用户名密码不让乱发,是防垃圾邮件吧 上面的例子比较详细了。首先要你的邮件服务器的协议中支持不认证的方式,也就是不使用User+pass的方式登录发Mail。然后程序中才可以使用 不认证的方式。 简单邮件<a href="mailto:[email protected]?subject=ccc&body=xxxyyy"> 当然可以不用帐号密码发邮件啦,不知各位是否用过类似邮件直投的软件。你也可以想想各个邮件服务器之间是如何投递邮件的,所以邮件直投是可以的先要通过dns协议获取要发送的目的邮箱的MX邮箱名,然后就可以通过SMTP向目的邮箱发送可以看看俺做的邮件直投工具,地址http://yycnet.yeah.net 下载专区Ymailer yyc_csdn (yyc) 你那给的不是网易的邮箱地址么?你能给出具体代码吗 access连接字符串出错了 javabean分页问题。帮忙看看有什么错误 struts2框架怎么弄到MyEclipse里 javamail出问题了 属性问题 struts跳转另一个项目的jsp或者.do请求的问题 jasperreport+ireport 怎么实现套打?分不够再加!!! HTML的低级问题:点击IE的后退,怎么调用上一个页面的JS呢? jbuilder里的混淆器好用吗?那个混淆器叫什么名称?哪里下载的到?我这里没有jbuilder 把asp改成jsp编写的程序,大侠帮忙阿!数据库改成sqlserver(1) 用java怎么对密码加密? 新手求助:JSP页面无法显示
props.put("mail.smtp.auth","false");
设置成false就不需要认证了,网上很多例子的,google一下,呵呵
* 用你自己的mailserver啊,在配置文件中写好
* 用户名、密码、邮件服务器,程序中读取出来
* 然后调用sendAttach方法就行啦。
*/
private static String host = Properties.getSystemProperty("mail.server");
private static String user = Properties.getSystemProperty("mail.server.user");
private static String password = Properties.getSystemProperty("mail.server.password");/**
* @from:发件人
* @to: 收件人
* @subject:邮件标题
* @subject:邮件内容
* @fileName:附件
*/
public static void sendAttach(String from, String to, String subject, String content, String fileName) {
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
if (from == null || from.trim().length() == 0) {
from = systemEmail;
}
try {
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);
Message message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(content, "text/html;charset=GB2312");
// attached
Date now = new Date();
long name = now.getTime();
BodyPart messageBodyPart2 = new MimeBodyPart();
messageBodyPart2.setFileName(name + "");
FileDataSource fileDataSource = new FileDataSource(fileName);
messageBodyPart2.setDataHandler(new DataHandler(fileDataSource));
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
multipart.addBodyPart(messageBodyPart2);
message.setContent(multipart);
message.saveChanges();
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
catch (Exception e) {
System.out.println(e);
}
}***************************************************************
做个广告^_^:欢迎加入我刚建立的群组:http://group.csdn.net/qwert
***************************************************************
public static void send(String from, String to, String subject, String content) {
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
if (from == null || from.trim().length() == 0) {
from = systemEmail;
}
try {
MailAuthenticator myauth = new MailAuthenticator(user, password);
Session mailSession = Session.getInstance(props, myauth);
mailSession.setDebug(true);
Message message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setText(content);
message.saveChanges();
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
catch (Exception e) {
System.out.println(e);
}
}
这个类怎么写啊
private String strUser;
private String strPwd;
public MailAuthenticator(String user, String password) {
this.strUser = user;
this.strPwd = password;
}
首先要你的邮件服务器的协议中支持不认证的方式,也就是不使用User+pass的方式登录发Mail。
然后程序中才可以使用 不认证的方式。
<a href="mailto:[email protected]?subject=ccc&body=xxxyyy">
你也可以想想各个邮件服务器之间是如何投递邮件的,所以邮件直投是可以的
先要通过dns协议获取要发送的目的邮箱的MX邮箱名,然后就可以通过SMTP向目的邮箱发送
可以看看俺做的邮件直投工具,地址http://yycnet.yeah.net 下载专区Ymailer
(yyc) 你那给的不是网易的邮箱地址么?
你能给出具体代码吗