props.put("mail.smtp.auth", "true");
props.put("mail.smtp.user", userId);
props.put("mail.smtp.password",password);
session = javax.mail.Session.getInstance(props,new MyAuthenticator(userId, password));其中的MyAuthenticatorimport javax.mail.*;public class MyAuthenticator extends Authenticator{
String userId;
String password;
public MyAuthenticator(String userId, String password){
this.userId = userId;
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userId, password);
}
}
props.put("mail.smtp.user", userId);
props.put("mail.smtp.password",password);
session = javax.mail.Session.getInstance(props,new MyAuthenticator(userId, password));其中的MyAuthenticatorimport javax.mail.*;public class MyAuthenticator extends Authenticator{
String userId;
String password;
public MyAuthenticator(String userId, String password){
this.userId = userId;
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userId, password);
}
}
解决方案 »
- 请麻烦高手帮我写个翻转整数的递归算法!
- 100分:实现这样一个功能:读取一个txt文件,列出总共有多少个单词,并且每个单次出现的频率是多少
- AudioData data = as.getData();
- KeyStroke
- @@@@@@@@@@@@@@@请教关于jbuilder2005
- 请问如何实现JTable的多列行头?《发几篇swing中关于JTable中的运用-5》中给的列子不能运行啊!
- 求救:关于Windows环境下桌面程序设计的问题
- 高分求解小问题
- 在JEditorPane上如何实现Undo/Redo?
- 半夜苦读!!明早起床!!请各位师傅鼓励我一下吧!!
- 如何设置JTable的列宽度
- 寻求开发机会
import javax.mail.internet.*;
import java.util.*;
public class sendMail
{
public static void main(String args[]) throws Exception
{ String host = "smtp.sina.com.cn";
String from = "[email protected]";
String to = "[email protected]";
String username = "javamail";
String password = "password"; // Get system properties
// Properties props = System.getProperties(); 很多例子中是这样的,其实下面这句更好,可以用在applet中
Properties props = new Properties(); // Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true"); //这样才能通过验证 // Get session
Session session = Session.getDefaultInstance(props); // watch the mail commands go by to the mail server
session.setDebug(true); // Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail"); // Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
}
import javax.mail.internet.*;
import java.util.*;
public class sendMail
{
public static void main(String args[]) throws Exception
{ String host = "smtp.sina.com.cn";
String from = "[email protected]";
String to = "[email protected]";
String username = "javamail";
String password = "password"; // Get system properties
// Properties props = System.getProperties(); 很多例子中是这样的,其实下面这句更好,可以用在applet中
Properties props = new Properties(); // Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true"); //这样才能通过验证 // Get session
Session session = Session.getDefaultInstance(props); // watch the mail commands go by to the mail server
session.setDebug(true); // Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail"); // Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
}