关于java发送邮件的问题(高手请进) 我想知道用java编写个发邮件的程序中,用不用向服务器发送用户名和密码。它的格式是什么我编写的一个程序中没有用户名和密码,好像发送不错去 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.mail.*; import java.util.*; import javax.mail.internet.*;public class SenderWithSMTPVer { String host=""; String user=""; String password=""; public void setHost(String host) { this.host=host; } public void setAccount( String user,String password) { this.user=user; this.password=password; } public void send(String from,String to, String subject,String content) { Properties props = new Properties(); props.put("mail.smtp.host", host); //指定SMTP服务器 props.put("mail.smtp.auth", "true"); //指定是否需要SMTP验证 try { Session mailSession = Session.getDefaultInstance(props); mailSession.setDebug(true); //是否在控制台显示debug信息 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); } } public static void main(String args[]) { SenderWithSMTPVer sm=new SenderWithSMTPVer(); sm.setHost("smtp.163.com"); //指定要使用的邮件服务器 sm.setAccount("abc","123"); //指定帐号和密码 /* * @param String 发件人的地址 * @param String 收件人地址 * @param String 邮件标题 * @param String 邮件正文 */ sm.send("[email protected]","[email protected]","标题","内容"); } } Java拼图游戏算法上的问题 如何用JAVA编写日历? 还是关于tomcat的 谁可以帮我分析一下这名话?关于面向对象的。 急求旋转图形的方法! JS中,怎么实现日期与天数相加后,返回如2005-10-23的样子 时间问题 学习代码!发放中…… java新手:我装的jbuilder6.0为什么找不到类包 请教一个小问题. 谁有xml学习例子 为什么中级程序设计中有许多接口和抽象类??
import javax.mail.*;
import java.util.*;
import javax.mail.internet.*;
public class SenderWithSMTPVer
{
String host="";
String user="";
String password=""; public void setHost(String host)
{
this.host=host;
} public void setAccount(
String user,String password)
{
this.user=user;
this.password=password;
} public void send(String from,String to,
String subject,String content)
{
Properties props = new Properties();
props.put("mail.smtp.host", host);
//指定SMTP服务器
props.put("mail.smtp.auth", "true");
//指定是否需要SMTP验证
try
{
Session mailSession = Session.getDefaultInstance(props); mailSession.setDebug(true);
//是否在控制台显示debug信息 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);
} } public static void main(String args[])
{
SenderWithSMTPVer sm=new SenderWithSMTPVer(); sm.setHost("smtp.163.com");
//指定要使用的邮件服务器
sm.setAccount("abc","123");
//指定帐号和密码 /*
* @param String 发件人的地址
* @param String 收件人地址
* @param String 邮件标题
* @param String 邮件正文
*/
sm.send("[email protected]","[email protected]","标题","内容");
} }