Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hello, i'm trying to make a mail test w/out attachment, but i have a bit of a problem,
here is the code


Java
public boolean send() throws MessagingException {
		Properties props = _setProperties();

		if (!_user.equals("") && !_pass.equals("") && _to.length > 0
				&& !_from.equals("") && !_subject.equals("")
				&& !_body.equals("")) {
			Session session = Session.getInstance(props, this);

			MimeMessage msg = new MimeMessage(session);

			msg.setFrom(new InternetAddress(_from));

			InternetAddress[] addressTo = new InternetAddress[_to.length];
			for (int i = 0; i < _to.length; i++) {
				addressTo[i] = new InternetAddress(_to[i]);
			}
			msg.setRecipients(MimeMessage.RecipientType.TO, addressTo);

			msg.setSubject(_subject);
			msg.setSentDate(new Date());

			// setup message body
			BodyPart messageBodyPart = new MimeBodyPart();
			messageBodyPart.setText(_body);
			

			// send email
			Transport.send(msg);

			return true;
		} else {
			return false;
		}
	}




private Properties _setProperties() {
		Properties props = new Properties();

		props.put("mail.smtp.host", _host);

		props.put("mail.debug", "true");

		props.put("mail.smtp.auth", "true");

		props.put("mail.smtp.port", _port);
		props.put("mail.smtp.socketFactory.port", _sport);
		props.put("mail.smtp.socketFactory.class",
				"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.socketFactory.fallback", "false");

		return props;
	}

this didn't work, because it lunches the exception in the Transport.send(msg) part
any ideas ?
thanks !!
Posted
Updated 5-Jul-12 6:37am
v2
Comments
[no name] 5-Jul-12 12:41pm    
Knowing what the exception is, is a real good place to start....
ZurdoDev 5-Jul-12 16:16pm    
What is the error?
[no name] 11-Jul-12 17:43pm    
Until you give people the information they would need to help you, constantly bumping your question with fake answers is not going to do any good.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900