Research Log of Web Science Students

Computer Science is not simply programming

Email Sent! =)

leave a comment »

After many weeks of error searching and pondering why this send email implementation won’t work on Projectrix, I’ve decided to follow this implementation. Guess what? It worked!


private String sendEmail(Project project) throws Exception{
	Properties props = new Properties();
	Session session = Session.getDefaultInstance(props, null);
	String msgBody = project.getOwner()+" invited you to assess "+project.getTitle()+
		". Go to this link to view the project: "+project.getLink()+". Thank you.";
	String message = "";
	try {
		Message msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress(project.getOwner(), project.getOwner()));
		List<String> assessors = project.getAssessors();
		for (String assessor: assessors) {
			msg.addRecipient(Message.RecipientType.BCC,
			new InternetAddress(assessor, assessor));
			msg.setSubject("Projectrix: You've been invited to assess "+project.getTitle()+".");
			message = message.concat("Email sent to "+assessor+".");
		}
		msg.setText(msgBody);
		Transport.send(msg);
	} catch (AddressException e) {
		message = message.concat("FAIL! addressexception"+ e+".");
	} catch (MessagingException e) {
		message = message.concat("FAIL! messagingexception"+ e+".");
	}
	log.info("message: "+message);
	return message;

}

It really helped that I set up a sandbox (as recommended by Jeune) and tried the email implementation there first before doing it on Projectrix. Now, I’m refactoring my code so it won’t send 2 emails of the same subject and content anymore. I’m investigating why this happens.

Advertisements

Written by Daniela

November 21, 2009 at 12:35 am

Posted in ProjectriX

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: