邮件发送 java mail

根据需要写了一个java发送邮件的程序
		Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.126.com");
        props.put("mail.smtp.auth", "true");
        Session session = Session.getDefaultInstance(props, new Authenticator()
        {
            @Override
            protected PasswordAuthentication getPasswordAuthentication()
            {
                return new PasswordAuthentication("[email protected]", "XXXXX");
            }
        });
        session.setDebug(false);

        try {
        	Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("[email protected]", "生产服务监控程序"));
			message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
			message.setSubject("告警通知");
	        message.setText("AAAAAAAAA这是一封邮件啊AAAAAAAa");
	        message.setSentDate(new Date());

	        Transport.send(message);
		} catch (Exception e) {
			e.printStackTrace();
		} 
        
	

你可能感兴趣的:(java,qq)