當前位置: 首頁>>代碼示例>>Java>>正文


Java Session.setDebug方法代碼示例

本文整理匯總了Java中javax.mail.Session.setDebug方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.setDebug方法的具體用法?Java Session.setDebug怎麽用?Java Session.setDebug使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.Session的用法示例。


在下文中一共展示了Session.setDebug方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendMsg

import javax.mail.Session; //導入方法依賴的package包/類
public boolean sendMsg(String recipient, String subject, String content)
		throws MessagingException {
	// Create a mail object
	Session session = Session.getInstance(props, new Authenticator() {
		// Set the account information session,transport will send mail
		@Override
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(Constants.MAIL_USERNAME, Constants.MAIL_PASSWORD);
		}
	});
	session.setDebug(true);
	Message msg = new MimeMessage(session);
	try {
		msg.setSubject(subject);			//Set the mail subject
		msg.setContent(content,"text/html;charset=utf-8");
		msg.setFrom(new InternetAddress(Constants.MAIL_USERNAME));			//Set the sender
		msg.setRecipient(RecipientType.TO, new InternetAddress(recipient));	//Set the recipient
		Transport.send(msg);
		return true;
	} catch (Exception ex) {
		ex.printStackTrace();
		System.out.println(ex.getMessage());
		return false;
	}

}
 
開發者ID:ICT-BDA,項目名稱:EasyML,代碼行數:27,代碼來源:JavaMail.java

示例2: sendMail

import javax.mail.Session; //導入方法依賴的package包/類
private static void sendMail()
        throws MessagingException, IOException {
    Session session = Session.getInstance(getMailProps(), new javax.mail.Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(
                    getVal("username"),
                    getVal("password"));
        }
    });
    session.setDebug(getBoolVal("mail.debug"));
    LOG.info("Compiling Mail before Sending");
    Message message = createMessage(session);
    Transport transport = session.getTransport("smtp");
    LOG.info("Connecting to Mail Server");
    transport.connect();
    LOG.info("Sending Mail");
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();
    LOG.info("Reports are sent to Mail");
    clearTempZips();
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:23,代碼來源:Mailer.java

示例3: sendHtmlMail

import javax.mail.Session; //導入方法依賴的package包/類
/**
 * 以HTML格式發送郵件
 * 
 * @param mailInfo
 *            待發送的郵件信息
 */
public boolean sendHtmlMail(MailSenderObj mailInfo) {
	// 判斷是否需要身份認證
	MyAuthenticator authenticator = null;
	Properties pro = mailInfo.getProperties();
	// 如果需要身份認證,則創建一個密碼驗證器
	if (mailInfo.isValidate()) {
		authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
	}
	// 根據郵件會話屬性和密碼驗證器構造一個發送郵件的session
	Session sendMailSession = Session.getDefaultInstance(pro, authenticator);
	sendMailSession.setDebug(true);// 設置debug模式 在控製台看到交互信息
	try {
		// 根據session創建一個郵件消息
		Message mailMessage = new MimeMessage(sendMailSession);
		// 創建郵件發送者地址
		Address from = new InternetAddress(mailInfo.getFromAddress());
		// 設置郵件消息的發送者
		mailMessage.setFrom(from);
		// 創建郵件的接收者地址,並設置到郵件消息中
		String[] asToAddr = mailInfo.getToAddress();
		if (asToAddr == null) {
			logger.debug("郵件發送失敗,收信列表為空" + mailInfo);
			return false;
		}
		for (int i=0; i<asToAddr.length; i++) {
			if (asToAddr[i] == null || asToAddr[i].equals("")) {
				continue;
			}
			Address to = new InternetAddress(asToAddr[i]);
			// Message.RecipientType.TO屬性表示接收者的類型為TO
			mailMessage.addRecipient(Message.RecipientType.TO, to);
		}
		// 設置郵件消息的主題
		mailMessage.setSubject(mailInfo.getSubject());
		// 設置郵件消息發送的時間
		mailMessage.setSentDate(new Date());
		// MiniMultipart類是一個容器類,包含MimeBodyPart類型的對象
		Multipart mainPart = new MimeMultipart();
		// 創建一個包含HTML內容的MimeBodyPart
		BodyPart html = new MimeBodyPart();
		// 設置HTML內容
		html.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
		mainPart.addBodyPart(html);
		// 將MiniMultipart對象設置為郵件內容
		mailMessage.setContent(mainPart);
		// 發送郵件
		Transport.send(mailMessage);
		logger.info("發送郵件成功。" + mailInfo);
		return true;
	} catch (MessagingException ex) {
		logger.error("發送郵件失敗:" + ex.getMessage() + Arrays.toString(ex.getStackTrace()));
	}
	return false;
}
 
開發者ID:langxianwei,項目名稱:iot-plat,代碼行數:61,代碼來源:SimpleMailSender.java

示例4: main

import javax.mail.Session; //導入方法依賴的package包/類
public static void main(String[] args) {
      Properties props = new Properties();
      /** Parâmetros de conexão com servidor Gmail */
      props.put("mail.smtp.host", "smtp.gmail.com");
      props.put("mail.smtp.socketFactory.port", "465");
      props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.port", "465");

      Session session = Session.getDefaultInstance(props,
                  new javax.mail.Authenticator() {
                       protected PasswordAuthentication getPasswordAuthentication() 
                       {
                             return new PasswordAuthentication("[email protected]", "tjm123456");
                       }
                  });
      /** Ativa Debug para sessão */
      session.setDebug(true);
      try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("[email protected]")); //Remetente

            Address[] toUser = InternetAddress //Destinatário(s)
                       .parse("[email protected]");  
            message.setRecipients(Message.RecipientType.TO, toUser);
            message.setSubject("Enviando email com JavaMail");//Assunto
            message.setText("Enviei este email utilizando JavaMail com minha conta GMail!");
            /**Método para enviar a mensagem criada*/
            Transport.send(message);
            System.out.println("Feito!!!");
       } catch (MessagingException e) {
            throw new RuntimeException(e);
      }
}
 
開發者ID:Ronneesley,項目名稱:redesocial,代碼行數:36,代碼來源:Enviar_email.java

示例5: send

import javax.mail.Session; //導入方法依賴的package包/類
public void send(String to, String cc, String bcc, String subject,
        String content, JavamailConfig javamailConfig)
        throws MessagingException {
    logger.debug("send : {}, {}", to, subject);

    try {
        Properties props = createSmtpProperties(javamailConfig);
        String username = javamailConfig.getUsername();
        String password = javamailConfig.getPassword();

        // 創建Session實例對象
        Session session = Session.getInstance(props, new SmtpAuthenticator(
                username, password));
        session.setDebug(false);

        // 創建MimeMessage實例對象
        MimeMessage message = new MimeMessage(session);
        // 設置郵件主題
        message.setSubject(subject);
        // 設置發送人
        message.setFrom(new InternetAddress(username));
        // 設置發送時間
        message.setSentDate(new Date());
        // 設置收件人
        message.setRecipients(RecipientType.TO, InternetAddress.parse(to));
        // 設置html內容為郵件正文,指定MIME類型為text/html類型,並指定字符編碼為gbk
        message.setContent(content, "text/html;charset=gbk");

        // 保存並生成最終的郵件內容
        message.saveChanges();

        // 發送郵件
        Transport.send(message);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:38,代碼來源:JavamailService.java

示例6: sendTextEmail

import javax.mail.Session; //導入方法依賴的package包/類
public static void sendTextEmail(String recvEmail) {
	try { 
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", "smtp.qq.com");
		props.setProperty("mail.smtp.auth", "true");
		props.put("mail.smtp.ssl.enable", "true");
		props.put("mail.smtp.socketFactory.port",  "994");
		Session session = Session.getInstance(props, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication("463112653", "manllfvunnfwbjhh");
			}
		});
		session.setDebug(true);
		Message msg = new MimeMessage(session);
		msg.setSubject("Hello Vme");
		//整個郵件的MultiPart(不能直接加入內容,需要在bodyPart中加入)
		Multipart emailPart = new MimeMultipart();
		MimeBodyPart attr1 = new MimeBodyPart();
		attr1.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/2601169057.png")));
		attr1.setFileName("tip.pic");
		
		MimeBodyPart attr2 = new MimeBodyPart();
		attr2.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
		attr2.setFileName(MimeUtility.encodeText("哦圖像"));
		
		MimeBodyPart content = new MimeBodyPart();
		MimeMultipart contentPart = new MimeMultipart();
		
		MimeBodyPart imgPart = new MimeBodyPart();
		imgPart.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
		imgPart.setContentID("pic");
		
		MimeBodyPart htmlPart = new MimeBodyPart();
		htmlPart.setContent("<h1><a href='www.baidu.com'>百度一下</a><img src='cid:pic'/></h1>", "text/html;charset=utf-8");
		
		contentPart.addBodyPart(imgPart);
		contentPart.addBodyPart(htmlPart);
		content.setContent(contentPart);
		
		emailPart.addBodyPart(attr1);
		emailPart.addBodyPart(attr2);
		emailPart.addBodyPart(content);
		msg.setContent(emailPart);
		
		msg.setFrom(new InternetAddress("[email protected]"));
		msg.setRecipients(RecipientType.TO, InternetAddress.parse("[email protected],[email protected]"));
		msg.setRecipients(RecipientType.CC, InternetAddress.parse("[email protected],[email protected]"));
		Transport.send(msg);
	} catch (Exception e) {
		e.printStackTrace();
	} 
}
 
開發者ID:Fetax,項目名稱:Fetax-AI,代碼行數:55,代碼來源:EmailHelper.java

示例7: send

import javax.mail.Session; //導入方法依賴的package包/類
/**
 * 發送郵件
 * 
 * @param email-收件人
 * @throws Exception
 * @return new password
 */
public static String send(String email, String username) throws Exception {

	String pwd = getRandomString(6);
	
	// 2. 根據配置創建會話對象, 用於和郵件服務器交互
	Session session = Session.getDefaultInstance(props);
	session.setDebug(true); // 設置為debug模式, 可以查看詳細的發送 log

	// 3. 創建一封郵件
	MimeMessage message = createMimeMessage(session, myEmailAccount, email, username,pwd);

	// 4. 根據 Session 獲取郵件傳輸對象
	Transport transport = session.getTransport();

	// 5. 使用 郵箱賬號 和 密碼 連接郵件服務器, 這裏認證的郵箱必須與 message 中的發件人郵箱一致, 否則報錯
	//
	// PS_01: 成敗的判斷關鍵在此一句, 如果連接服務器失敗, 都會在控製台輸出相應失敗原因的 log,
	// 仔細查看失敗原因, 有些郵箱服務器會返回錯誤碼或查看錯誤類型的鏈接, 根據給出的錯誤
	// 類型到對應郵件服務器的幫助網站上查看具體失敗原因。
	//
	// PS_02: 連接失敗的原因通常為以下幾點, 仔細檢查代碼:
	// (1) 郵箱沒有開啟 SMTP 服務;
	// (2) 郵箱密碼錯誤, 例如某些郵箱開啟了獨立密碼;
	// (3) 郵箱服務器要求必須要使用 SSL 安全連接;
	// (4) 請求過於頻繁或其他原因, 被郵件服務器拒絕服務;
	// (5) 如果以上幾點都確定無誤, 到郵件服務器網站查找幫助。
	//
	// PS_03: 仔細看log, 認真看log, 看懂log, 錯誤原因都在log已說明。
	transport.connect(myEmailAccount, myEmailPassword);

	// 6. 發送郵件, 發到所有的收件地址, message.getAllRecipients() 獲取到的是在創建郵件對象時添加的所有收件人,
	// 抄送人, 密送人
	transport.sendMessage(message, message.getAllRecipients());

	// 7. 關閉連接
	transport.close();
	
	return pwd;
}
 
開發者ID:miracle857,項目名稱:weibo,代碼行數:47,代碼來源:Mail.java

示例8: send

import javax.mail.Session; //導入方法依賴的package包/類
/**
 * @Title: send
 * @Description: TODO(發送帶附件的郵件)
 * @author [email protected] (苟誌強)
 * @date  2017-6-6 下午4:29:56
 * @param to 接收用戶賬戶
 * @param title 郵件標題
 * @param content 郵件內容
 * @param affix 附件路徑
 * @param affixName 發送後顯示名稱
 * @return 是否發送成功
 */
public static boolean send(String to,String title,String content,String affix,String affixName) {
	Properties props = new Properties();
	//設置發送郵件的郵件服務器的屬性(這裏使用網易的smtp服務器)
	props.put("mail.smtp.host", host);
	//需要經過授權,也就是有戶名和密碼的校驗,這樣才能通過驗證
	props.put("mail.smtp.auth", "true");
	//用剛剛設置好的props對象構建一個session
	Session session = Session.getDefaultInstance(props);
	//有了這句便可以在發送郵件的過程中在console處顯示過程信息,供調試使
	//用(你可以在控製台(console)上看到發送郵件的過程)
	session.setDebug(true);
	//用session為參數定義消息對象
	MimeMessage message = new MimeMessage(session);
	try{
		//加載發件人地址
		message.setFrom(new InternetAddress(from));
		//加載收件人地址
		message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
		//加載標題
		message.setSubject(title);
		// 向multipart對象中添加郵件的各個部分內容,包括文本內容和附件
		Multipart multipart = new MimeMultipart();         

		//設置郵件的文本內容
		BodyPart contentPart = new MimeBodyPart();
		contentPart.setText(content);
		multipart.addBodyPart(contentPart);
		//添加附件
		if(affix!=null&&!"".equals(affix)&&affixName!=null&&!"".equals(affixName)){
			BodyPart messageBodyPart= new MimeBodyPart();
			DataSource source = new FileDataSource(affix);
			//添加附件的內容
			messageBodyPart.setDataHandler(new DataHandler(source));
			//添加附件的標題
			messageBodyPart.setFileName(MimeUtility.encodeText(affixName));
			multipart.addBodyPart(messageBodyPart);
		}
		//將multipart對象放到message中
		message.setContent(multipart);
		//保存郵件
		message.saveChanges();
		//   發送郵件
		Transport transport = session.getTransport("smtp");
		//連接服務器的郵箱
		transport.connect(host, user, pwd);
		//把郵件發送出去
		transport.sendMessage(message, message.getAllRecipients());
		transport.close();
		return true;
	}catch(Exception e){
		e.printStackTrace();
		return false;
	}
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:67,代碼來源:EmailUtil.java

示例9: sendTextEmail

import javax.mail.Session; //導入方法依賴的package包/類
/**
 * 
 * @param recvEmail 收件人可多個,用","隔開
 * @param title  標題
 * @param text   郵件內容
 */
public static void sendTextEmail(String recvEmail, String title, String text) {
	try { 
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", "smtp.qq.com");
		props.setProperty("mail.smtp.auth", "true");
		props.put("mail.smtp.ssl.enable", "true");
		props.put("mail.smtp.socketFactory.port",  "994");
		Session session = Session.getInstance(props, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication("463112653", "manllfvunnfwbjhh");
			}
		});
		session.setDebug(true);
		Message msg = new MimeMessage(session);
		msg.setSubject(title);
		msg.setText(text);
		msg.setFrom(new InternetAddress("[email protected]"));
		msg.setRecipients(RecipientType.TO, InternetAddress.parse(recvEmail));
		msg.setRecipients(RecipientType.CC, InternetAddress.parse(recvEmail));
		Transport.send(msg);
	} catch (Exception e) {
		e.printStackTrace();
	} 
}
 
開發者ID:Awesky,項目名稱:awe-awesomesky,代碼行數:33,代碼來源:EmailHelper.java

示例10: sendemail

import javax.mail.Session; //導入方法依賴的package包/類
/**
 *  Sends an email message.
 *
 * @param  emailHost                    host name of the email server
 * @param  emailFrom                    "from" name to be used in email messages
 * @param  emailAddrs                   array of "to" names for email messages
 * @param  emailSubject                 initial part of the email "Subject" line
 * @param  msgtext                      The message text.
 * @exception  MessagingException       DESCRIPTION
 * @exception  NoSuchProviderException  DESCRIPTION
 * @exception  IOException              DESCRIPTION
 */

void sendemail(
		String emailHost,
		String emailFrom,
		String[] emailAddrs,
		String emailSubject,
		String msgtext)
		 throws MessagingException, NoSuchProviderException, IOException {
	int ii;

	// Convert strange chars to %xx hex encoding.
	// Java's MimeMessage will automatically convert the ENTIRE
	// message to some strange encoding if the message
	// contains a single weird char.

	StringBuffer finalBuf = new StringBuffer();
	for (ii = 0; ii < msgtext.length(); ii++) {
		char cc = msgtext.charAt(ii);
		if ((cc >= 0x20 && cc < 0x7f)
				 || cc == '\t'
				 || cc == '\n'
				 || cc == '\f'
				 || cc == '\r') {
			finalBuf.append(cc);
		} else {
			String hexstg = Integer.toHexString(cc);
			if (hexstg.length() == 1) {
				hexstg = '0' + hexstg;
			}
			finalBuf.append('%');
			finalBuf.append(hexstg.toUpperCase());
		}
	}

	boolean debug = false;
	Properties props = new Properties();
	if (debug) {
		props.put("mail.debug", "true");
	}
	props.put("mail.smtp.host", emailHost);
	Session session = Session.getInstance(props, null);
	session.setDebug(debug);

	MimeMessage msg = new MimeMessage(session);
	msg.setFrom(new InternetAddress(emailFrom));

	InternetAddress[] recips = new InternetAddress[emailAddrs.length];
	for (ii = 0; ii < emailAddrs.length; ii++) {
		recips[ii] = new InternetAddress(emailAddrs[ii]);
	}
	msg.setRecipients(RecipientType.TO, recips);
	msg.setSubject(emailSubject);
	msg.setContent(finalBuf.toString(), "text/plain");
	Transport.send(msg);
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:68,代碼來源:Idmap.java

示例11: sendPassword

import javax.mail.Session; //導入方法依賴的package包/類
public static void sendPassword(String receiveMailAccount, String password) throws Exception {

        Properties props = new Properties();                    
        props.setProperty("mail.transport.protocol", "smtp");  

        props.setProperty("mail.smtp.host", myEmailSMTPHost);
        props.setProperty("mail.smtp.auth", "true"); 
        

        Session session = Session.getDefaultInstance(props);
        session.setDebug(true);                         
   
        MimeMessage message = createMimeMessage(session, myEmailAccount, receiveMailAccount, password);

     
        Transport transport = session.getTransport();

        transport.connect(myEmailAccount, myEmailPassword);


        transport.sendMessage(message, message.getAllRecipients());

        transport.close();
    }
 
開發者ID:632team,項目名稱:EasyHousing,代碼行數:25,代碼來源:Tool.java

示例12: sendMail

import javax.mail.Session; //導入方法依賴的package包/類
public boolean sendMail(String to,String otp) throws MessagingException 
{
	String host="smtp.gmail.com";
	String username="";//emailid
	String password="";//emailid password
	String from=" ";// email from which u have to send
	String subject="One Time Password";
	String body="Your One Time passsword is "+otp;
	
	boolean sessionDebug=false;
	
	Properties props=System.getProperties();
	props.put("mail.host",host);
	props.put("mail.transport.protocol","smtp");
	props.put("mail.smtp.starttls.enable","true");
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.debug", "true");
	props.put("mail.smtp.socketFactory.port", "465");
	props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
	props.put("mail.smtp.socketFactory.fallback", "false");
	props.put("mail.smtp.host", "smtp.gmail.com");
	props.put("mail.smtp.port", "25"); 
	
	Session mailSession=Session.getDefaultInstance(props,null);
	mailSession.setDebug(sessionDebug);
	
	Message msg=new MimeMessage(mailSession);
	msg.setFrom(new InternetAddress(from));
	InternetAddress [] address={new InternetAddress(to)};
	msg.setRecipients(Message.RecipientType.TO,address);
	msg.setSubject(subject);
	msg.setSentDate(new Date());
	msg.setText(body);

	Transport tr=mailSession.getTransport("smtp");
	tr.connect(host,username,password);
	msg.saveChanges();
	tr.sendMessage(msg,msg.getAllRecipients());
	tr.close();
	//Transport.send(msg);
	return true;
}
 
開發者ID:nishittated,項目名稱:OnlineElectionVotingSystem,代碼行數:43,代碼來源:PasswordMail.java

示例13: sendMail1

import javax.mail.Session; //導入方法依賴的package包/類
public boolean sendMail1(String to,String passwrd, String link) throws MessagingException
{
	String host="smtp.gmail.com";
	String username="	 ";//emailid
	String password="";//emailid password
	String from=" ";// email from which u have to send
	String subject="Website Password";
	String body="Your website password is "+passwrd+"  Please click to reset "+link;
	boolean sessionDebug=false;
	
	Properties props=System.getProperties();
	props.put("mail.host",host);
	props.put("mail.transport.protocol","smtp");
	props.put("mail.smtp.starttls.enable","true");
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.debug", "true");
	props.put("mail.smtp.socketFactory.port", "465");
	props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
	props.put("mail.smtp.socketFactory.fallback", "false");
	props.put("mail.smtp.host", "smtp.gmail.com");
	props.put("mail.smtp.port", "25"); 
	
	Session mailSession=Session.getDefaultInstance(props,null);
	mailSession.setDebug(sessionDebug);

	Message msg=new MimeMessage(mailSession);
	msg.setFrom(new InternetAddress(from));
	
	InternetAddress [] address={new InternetAddress(to)};
	msg.setRecipients(Message.RecipientType.TO,address);
	msg.setSubject(subject);
	msg.setSentDate(new Date());
	msg.setText(body);
	
	Transport tr=mailSession.getTransport("smtp");
	tr.connect(host,username,password);
	msg.saveChanges();
	tr.sendMessage(msg,msg.getAllRecipients());
	tr.close();
			//Transport.send(msg);
	return true;
}
 
開發者ID:nishittated,項目名稱:OnlineElectionVotingSystem,代碼行數:43,代碼來源:PasswordMail.java

示例14: sendMail2

import javax.mail.Session; //導入方法依賴的package包/類
public boolean sendMail2(String to, String link) throws AddressException, MessagingException {

		String host="smtp.gmail.com";
		String username="	 ";//emailid
		String password="";//emailid password
		String from=" ";// email from which u have to send
		String subject="Website Password";
		String body="Activation Link"+link+"Please click to reset "+link;
		boolean sessionDebug=false;
		
		Properties props=System.getProperties();
		props.put("mail.host",host);
		props.put("mail.transport.protocol","smtp");
		props.put("mail.smtp.starttls.enable","true");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.debug", "true");
		props.put("mail.smtp.socketFactory.port", "465");
		props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.socketFactory.fallback", "false");
		props.put("mail.smtp.host", "smtp.gmail.com");
		props.put("mail.smtp.port", "25"); 
		
		Session mailSession=Session.getDefaultInstance(props,null);
		mailSession.setDebug(sessionDebug);
	
		Message msg=new MimeMessage(mailSession);
		msg.setFrom(new InternetAddress(from));
	
		InternetAddress [] address={new InternetAddress(to)};
		msg.setRecipients(Message.RecipientType.TO,address);
		msg.setSubject(subject);
		msg.setSentDate(new Date());
		msg.setText(body);
	
		Transport tr=mailSession.getTransport("smtp");
		tr.connect(host,username,password);
		msg.saveChanges();
		tr.sendMessage(msg,msg.getAllRecipients());
		tr.close();
			//Transport.send(msg);
		return true;
	}
 
開發者ID:nishittated,項目名稱:OnlineElectionVotingSystem,代碼行數:43,代碼來源:PasswordMail.java

示例15: main

import javax.mail.Session; //導入方法依賴的package包/類
public static void main(String[] args) {
	try {
		final String host = "smtp.qq.com";// ����QQ�����smtp��������ַ
		final String port = "25"; // �˿ں�
		/*
		 * Properties��һ�����Զ�����������Session����
		 */
		final Properties props = new Properties();
		props.setProperty("mail.smtp.host", host);
		props.setProperty("mail.smtp.port", port);
		props.setProperty("mail.smtp.auth", "true");
		props.setProperty("mail.smtp.ssl.enable", "false");// "true"
		props.setProperty("mail.smtp.connectiontimeout", "5000");
		final String user = "******@qq.com";// �û���
		final String pwd = "******";// ����
		/*
		 * Session�ඨ����һ���������ʼ��Ի���
		 */
		final Session session = Session.getInstance(props, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				// ��¼�û�������
				return new PasswordAuthentication(user, pwd);
			}
		});
		session.setDebug(true);
		/*
		 * Transport�����������ʼ��� �������smtp��transport���Զ�����smtpЭ�鷢���ʼ���
		 */
		final Transport transport = session.getTransport("smtp");// "smtps"
		transport.connect(host, user, pwd);
		/*
		 * Message������������ʵ�ʷ��͵ĵ����ʼ���Ϣ
		 */
		final MimeMessage message = new MimeMessage(session);
		message.setSubject("�ʼ�����");
		// ��Ϣ�����߽���������(������ַ���dz�)���ռ��˿������dz��������趨��
		message.setFrom(new InternetAddress(user, "��ʦ��"));
		message.addRecipients(Message.RecipientType.TO, new InternetAddress[] {
				// ��Ϣ������(�ռ���ַ���dz�)
				// ��������dz�ò��û�п���Ч��
				new InternetAddress("[email protected]", "��ʦ��"), });
		message.saveChanges();

		// �����ʼ����ݼ������ʽ
		// ��һ���������Բ�ָ�����룬��"text/plain"�����ǽ�������ʾ�����ַ�
		message.setContent("�ʼ�����..", "text/plain;charset=UTF-8");
		// ����
		// transport.send(message);
		Transport.send(message);
		transport.close();
	} catch (final Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:57,代碼來源:Mail_POP3.java


注:本文中的javax.mail.Session.setDebug方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。