• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error while sending a message

 
Jayashree Gopal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a simple Java program which i am using to send a message from one email id to another. I am using a linux m/c with squid for our proxy. WHen i try to execute the program, i find tht the control does not pass into the try block at all. COuld somehow let me know my mistake.
Here is the code:
public class MailMessageWithCommands
{
public static void main(String args[])
{
try
{
String host = null;
String from = args[1];
String to = args[2];
Properties props = new Properties();
props.put("proxyHost","196.100.110.4");
props.put("proxyPort","25");
props.put("mail.smtp.host",host);
System.out.println("properties");
Session newSession = Session.getInstance(System.getProperties(),null);
System.out.println("session");
MimeMessage message = new MimeMessage(newSession);
System.out.println("MimeMessage");
message.setFrom(new InternetAddress(from));
System.out.println("from");
message.setRecipients(Message.RecipientType.TO,to);
System.out.println("to");
message.setSubject("Hello");
System.out.println("subject");
message.setText("Using JavaMail for the first time");
System.out.println("text");
//Transport transp = new Transport(newSession,host);
Transport.send(message);
System.out.println("transport");
}
catch(AddressException e1)
{
System.out.println(e1.getMessage());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("Message sent Successfully");
}
}
I tried to use system.getProperties.put()...however,it gave me a compile time error.
I even tired to pass the ip add and the port of the m/c however, it gives me an error while sending. It always listens to port 25,instead of the port no tht i specify.
Thanks in advance.
Jayashree
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!