⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailsender.java

📁 短信发送
💻 JAVA
字号:
/**
 * @CreatedDate Nov 4, 2008
 */
package com.jdev.mail;

import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.Authenticator;
//import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
//import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
//import javax.mail.internet.MimeMultipart;
import javax.mail.internet.AddressException; 
import java.security.Security;
import java.util.Date;   

/**
 * @author Lawrence
 *
 */
public class MailSender {

	/**
	 * @param args
	 */
	 public static void main(String[] args) throws AddressException, MessagingException {      
		  Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());      
//		  final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";      
		  // Get a Properties object      
		  Properties props = System.getProperties();      
		  props.setProperty("mail.smtp.host", "smtp.china.com");      
//		  props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);      
//		  props.setProperty("mail.smtp.socketFactory.fallback", "false");      
//		  props.setProperty("mail.smtp.port", "465");      
//		  props.setProperty("mail.smtp.socketFactory.port", "465");      
		  props.put("mail.smtp.auth", "true");      
		  final String username = "vma";      
		  final String password = "jelin1226";      
		  Session session = Session.getDefaultInstance(props, new Authenticator(){      
		      protected PasswordAuthentication getPasswordAuthentication() {      
		          return new PasswordAuthentication(username, password);      
		      }});      
		     
		       // -- Create a new message --      
		  Message msg = new MimeMessage(session);      
		     
		  // -- Set the FROM and TO fields --      
		  msg.setFrom(new InternetAddress(username + "@china.com"));      
		  msg.setRecipients(Message.RecipientType.TO,      
		    InternetAddress.parse("vma@china.com",false));      
		  msg.setSubject("Hello");      
		  msg.setText("How are you");      
		  msg.setSentDate(new Date());      
		  Transport.send(msg);      
		        
		  System.out.println("Message sent.");
		  
		  System.exit(0);
		 }      
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -