views:

213

answers:

2
 try{
        Properties props = new Properties();
        props.put("mail.smtp.host", "ipc-smtp.bits-pilani.ac.in");
        Session sess = Session.getInstance(props, null);
        sess.setDebug(true);
        Message msg = new MimeMessage(sess);
        InternetAddress addressFrom = new InternetAddress("[email protected]");
        msg.setFrom(addressFrom);
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
        msg.addHeader("MyHeaderName", "myHeaderValue");
        msg.setSubject("Test");
        msg.setContent("Yippe", "text/plain");
        Transport.send(msg);
        }catch(Exception exp){
           exp.printStackTrace();
        }

The error is javax.mail.MessagingException: 554 The mail was blocked due to zen-spamhaus RBL action

This is my college's smtp server.

+1  A: 

I would inform your college's IT dept and they should be able to handle the issue. Although since it appears they left an open relay, maybe not.

tbs
A: 
import javax.mail.*;    
import javax.mail.internet.*;

.....

public static void postMail(String[] recipients, String subject, String message, String from) throws MessagingException {
    Properties props = new Properties();
    props.put("mail.smtp.host", Util.getProperty("smtpHost"));
    Session session = Session.getDefaultInstance(props, null);
    Message msg = new MimeMessage(session);
    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);
    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++) {
        addressTo[i] = new InternetAddress(recipients[i]);
    }
    msg.setRecipients(Message.RecipientType.TO, addressTo);
    //msg.addHeader("MyHeaderName", "myHeaderValue");
    msg.setSubject(subject);
    msg.setContent(message, "text/html");
    Transport.send(msg);
}
tommaso