当前位置: 首页>>代码示例>>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;未经允许,请勿转载。