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


Java PasswordAuthentication類代碼示例

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


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

示例1: sendMail

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
public static void sendMail(String host, int port, String username, String password, String recipients,
		String subject, String content, String from) throws AddressException, MessagingException {
	
	Properties props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", host);
	props.put("mail.smtp.port", port);

	Session session = Session.getInstance(props, new javax.mail.Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(username, password);
		}
	});

	Message message = new MimeMessage(session);
	message.setFrom(new InternetAddress(from));
	message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
	message.setSubject(subject);
	message.setText(content);

	Transport.send(message);
}
 
開發者ID:bndynet,項目名稱:web-framework-for-java,代碼行數:24,代碼來源:MailHelper.java

示例2: sendMsg

import javax.mail.PasswordAuthentication; //導入依賴的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

示例3: createSession

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
/**
 * Creates a mail session from the underlying mail properties.
 * 
 * @return the mail session.
 */
public Session createSession() 
{
    Session session;
    if (username == null) 
    {
        session = Session.getInstance(properties);
    }
    else 
    {
        Authenticator auth = new Authenticator() 
        {
            public PasswordAuthentication getPasswordAuthentication() 
            {
                return new PasswordAuthentication(username,
                        password == null ? "" : password);
            }
        };
        session = Session.getInstance(properties, auth);
    }
    return session;
}
 
開發者ID:cecid,項目名稱:hermes,代碼行數:27,代碼來源:MailConnector.java

示例4: init

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
/**
 * 郵件監聽器
 */
//private List<EmailSendListener> emailSendListeners = new ArrayList<EmailSendListener>();

public void init() {
	final Properties properties = SysConfig.getProperties();
	this.theadPool = Executors.newFixedThreadPool(POOL_SIZE);
	this.session = Session.getDefaultInstance(properties,
			new Authenticator() {
				@Override
				protected PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication(properties
							.getProperty("mail.smtp.username"), properties
							.getProperty("mail.smtp.password"));
				}
			});
	username = properties.getProperty("mail.smtp.username");
	//設置調試模式(輸出調試信息)
	this.session.setDebug(false);
}
 
開發者ID:wrayzheng,項目名稱:webpage-update-subscribe,代碼行數:22,代碼來源:EmailServer.java

示例5: setReadyForEmail

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
public void setReadyForEmail(String username, String password) {
	props = new Properties();
	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() {
				@Override
				protected PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication(username, password);
				}
			});
	
	message = new MimeMessage(session);
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:20,代碼來源:SendEmailToUser.java

示例6: getSession

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
/**
 *
 * This method will create a new Mail Session
 *
 * @param smtpServer
 *            Mail server IP/FQDN
 * @param port
 *            SMTP port
 * @param sendFrom
 *            Sender's Email ID
 * @param password
 *            Email account Password
 * @param sendTo
 *            Receiver's Email address
 * @return
 *         Mail Session Object with Properties configured
 */
private static Session getSession(String smtpServer, String port, final String sendFrom, final String password) {
    Properties props = new Properties();
    props.put("mail.smtp.host", smtpServer);
    props.put("java.net.preferIPv4Stack", "true");
    props.put("mail.smtp.port", port);

    Session session = Session.getInstance(props, null);

    if (!StringUtils.isBlank(password)) {
        props.put("mail.smtp.socketFactory.port", port);
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");

        session = Session.getInstance(props, new javax.mail.Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(sendFrom, password);
            }
        });
    }

    return session;
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:41,代碼來源:EmailUtil.java

示例7: sendMail

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
private void sendMail(String subject, String body, MailSettings settings) throws MessagingException {

        Properties props = new Properties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.host", settings.getSmtpServer());
        props.put("mail.smtp.port", settings.getSmtpPort() + "");

        if (settings.getMode() == MailSettings.Mode.SSL) {
            props.put("mail.smtp.socketFactory.port", settings.getSmtpPort() + "");
            props.put("mail.smtp.socketFactory.class",
                    "javax.net.ssl.SSLSocketFactory");
        } else if (settings.getMode() == MailSettings.Mode.TLS) {
            props.put("mail.smtp.starttls.enable", "true");
        }

        props.put("mail.smtp.auth", settings.isUseAuth() + "");

        Session session;
        if (settings.isUseAuth()) {
            session = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(settings.getUser(), settings.getPass());
                }
            });
        } else {
            session = Session.getInstance(props);
        }

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(settings.getFrom()));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(settings.getTo()));
        message.setSubject(subject);
        message.setText(body);

        Transport.send(message);

    }
 
開發者ID:dainesch,項目名稱:HueSense,代碼行數:41,代碼來源:MailService.java

示例8: sendMail

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
public String sendMail() {
	
	mail.setPassword(Mailer.PA);
	mail.setHost(Mailer.HOST);
	mail.setSender(Mailer.SENDER);
	Properties properties = System.getProperties();
	properties.put("mail.smtp.host", mail.getHost());
	properties.put("mail.smtp.auth", "true");
	properties.put("mail.smtp.socketFactory.port", "465");    
       properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");     
       properties.put("mail.smtp.port", "465");    
	Session session = Session.getInstance(properties,
			new javax.mail.Authenticator() {
				protected PasswordAuthentication getPasswordAurhentication() {
					return new PasswordAuthentication(mail.getSender(), mail.getPassword());
				}
			});
	
	try {
		
		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress(mail.getSender()));
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(mail.getEmailId()));
		message.setSubject(mail.getSubject());
		message.setText(mail.getMessage());
		Transport.send(message, mail.getSender(),mail.getPassword());
		System.out.println("Mail Sent");
		return StatusCode.SUCCESS;
	} catch(Exception ex) {
		throw new RuntimeException("Error while sending mail" + ex);
	}
}
 
開發者ID:vishal1997,項目名稱:DiscussionPortal,代碼行數:33,代碼來源:SendMail.java

示例9: testSetSession

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
@Test
public void testSetSession()
{
	smsTestClient.initializeSMSClient("Memoranda", "8005551212", "T-Mobile");
	Session testSession;
	props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", "outlook.office365.com");
	props.put("mail.smtp.port", "587");
	testSession = Session.getInstance(props, new javax.mail.Authenticator()
	{
		protected PasswordAuthentication getPasswordAuthentication() 
		{
			return new PasswordAuthentication(smsTestClient.getUsername(), smsTestClient.getPassword());
		}
});
	smsTestClient.setSession(testSession);
}
 
開發者ID:ser316asu,項目名稱:Wilmersdorf_SER316,代碼行數:20,代碼來源:SMS_Test.java

示例10: sendMail

import javax.mail.PasswordAuthentication; //導入依賴的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

示例11: getSession

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
/**
 * 獲取用戶與郵件服務器的連接
 *
 * @param host     郵件主機名
 * @param username 發件人的用戶名
 * @param password 發件人的用戶名密碼
 * @return 返回指定用戶與指定郵件服務器綁定的一個連接(會話)
 */
public static Session getSession(String host, final String username,
                                 final String password) {
    // 設置配置文件,郵件主機和是否認證
    Properties property = new Properties();
    property.put("mail.host", host);
    property.put("mail.smtp.auth", "true");
    // 設置用戶名和密碼
    Authenticator auth = new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            // TODO Auto-generated method stub
            return new PasswordAuthentication(username, password);
        }
    };
    // 獲取與郵件主機的連接
    Session session = Session.getInstance(property, auth);
    return session;
}
 
開發者ID:FlyingHe,項目名稱:UtilsMaven,代碼行數:27,代碼來源:MailUtils.java

示例12: getMailSession

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
private Session getMailSession(){
	if(session==null){
		Properties properties = new Properties();
		properties.put("mail.smtp.host",smtpHost);
		if(StringUtils.isNotEmpty(smtpPort)){
			properties.put("mail.smtp.port",Integer.parseInt(smtpPort));
		}
		if(smtpIsAuth) {
			properties.put("mail.smtp.auth","true");
			session = Session.getDefaultInstance(properties,
					new Authenticator() {
				public PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication(smtpUser,smtpPassword);
				}
			});
		} else {
			session = Session.getDefaultInstance(properties);
		}
	}
	return session;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:22,代碼來源:EmailSender.java

示例13: authorizeWebShopEmail

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
public static Session authorizeWebShopEmail() throws MessagingException {
    Session session = null;
    final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
    Properties props = System.getProperties();
    props.setProperty("mail.smtp.host", "smtp.gmail.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");
    props.put("mail.debug", "true");
    props.put("mail.store.protocol", "pop3");
    props.put("mail.transport.protocol", "smtp");
    final String username = ApplicationProperties.SHOP_EMAIL;
    final String password = ApplicationProperties.SHOP_EMAIL_PASSWORD;
    session = Session.getDefaultInstance(props, new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });
    return session;
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:23,代碼來源:EmailActions.java

示例14: passwordAuthentication

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
public PasswordAuthentication passwordAuthentication()
{
	String userName=getDefaultUserName();
	//當前用戶在密碼表裏
	if (pwdProperties.containsKey(userName)) {
		//取出密碼,封裝好後返回
		return new PasswordAuthentication(userName, pwdProperties.getProperty(userName).toString());

	}
	else {
		//如果當前用戶不在密碼表裏就返回Null
		System.out.println("當前用戶不存在");
		return null;


	}

}
 
開發者ID:zhengshuheng,項目名稱:PatatiumWebUi,代碼行數:19,代碼來源:SendMail.java

示例15: getSenderSession

import javax.mail.PasswordAuthentication; //導入依賴的package包/類
public static Session getSenderSession(String host, final String user, final String password){
	Session session = null;
	logger.info("Creating email session for sending, host: "+ host +", user: "+ user+ ", password: ******");
	Properties props = new Properties();
	props.put("mail.smtp.host", host);
	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.getDefaultInstance(props,
			new javax.mail.Authenticator() {
		@Override
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(user, password);
		}
	});
	return session;
}
 
開發者ID:ntholi,項目名稱:generis,代碼行數:21,代碼來源:EmailHelper.java


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