Send mail through Java program. ERROR javax.mail.MessagingException: [EOF]
843834Apr 29 2008 — edited Apr 30 2008Hi,
i've a java Mail program which will send the mail thro smtp server.
when i try to execute this program im getting the error javax.mail.MessagingException: [EOF]
i've attached both code & error.
while running the program need to give the arguments
ex : java SendMail smtpserver frommailid tomailid subject body
please provide me the solution.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class SendMail {
public static void main(String[] args) {
try
{
String smtpServer=args[0];
String to=args[1];
String from=args[2];
String subject=args[3];
String body=args[4];
send(smtpServer, to, from, subject, body);
}
catch (Exception ex)
{
System.out.println("Usage: java SendMail"
+" smtpServer toAddress fromAddress subjectText bodyText");
}
System.exit(0);
}
public static void send(String smtpServer, String to, String from
, String subject, String body)
{
try
{
Properties props = System.getProperties();
props.put("mail.smtp.host", smtpServer);
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
msg.setSubject(subject);
msg.setText(body);
msg.setSentDate(new Date());
System.out.println("test 1--");
Transport.send(msg);
System.out.println("test 2--");
System.out.println("Message sent OK.");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
thanks for the help in advance.
regs
lal.