Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java mail problem

Reply
Thread Tools

java mail problem

 
 
puropagol
Guest
Posts: n/a
 
      07-03-2003
I wrote the following simple java mail program. While using the
program on Windows it is working fine with our ISP, but when I am
trying to run this on a solaris box .. I am getting a
javax.mail.MessagingException saying could not connect to mail host.
Both the machines are on the internet. Can anybody suggest what the
problem is ?

************************************************** ****************************
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

import com.sun.mail.smtp.SMTPTransport;

public class SendMail {

public static void sendMail(
String mailHost,
int mailPort,
String userName,
String password,
String from,
String to,
String subject,
String body) {

try {
Properties prop = System.getProperties();
prop.put("mail.smtp.host", mailHost);
Session session1 = Session.getInstance(prop, null);
MimeMessage msg = new MimeMessage(session1);
msg.setFrom(new InternetAddress(from));
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
msg.setSubject(subject);
msg.setContent(body, "text/plain");
SMTPTransport trans = new SMTPTransport(session1,new
URLName(mailHost));
trans.connect(mailHost,mailPort,userName,password) ;
System.out.println(trans.isConnected());
trans.sendMessage(msg, msg.getAllRecipients());
trans.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
************************************************** ****************************
 
Reply With Quote
 
 
 
 
Mikkel Heisterberg
Guest
Posts: n/a
 
      07-03-2003
I would start verifying the connection to SMTP server from the Solaris
box using telnet.

lekkim

puropagol wrote:
> I wrote the following simple java mail program. While using the
> program on Windows it is working fine with our ISP, but when I am
> trying to run this on a solaris box .. I am getting a
> javax.mail.MessagingException saying could not connect to mail host.
> Both the machines are on the internet. Can anybody suggest what the
> problem is ?
>
> ************************************************** ****************************
> import java.util.*;
> import javax.mail.*;
> import javax.mail.internet.*;
>
> import com.sun.mail.smtp.SMTPTransport;
>
> public class SendMail {
>
> public static void sendMail(
> String mailHost,
> int mailPort,
> String userName,
> String password,
> String from,
> String to,
> String subject,
> String body) {
>
> try {
> Properties prop = System.getProperties();
> prop.put("mail.smtp.host", mailHost);
> Session session1 = Session.getInstance(prop, null);
> MimeMessage msg = new MimeMessage(session1);
> msg.setFrom(new InternetAddress(from));
> msg.addRecipient(Message.RecipientType.TO, new
> InternetAddress(to));
> msg.setSubject(subject);
> msg.setContent(body, "text/plain");
> SMTPTransport trans = new SMTPTransport(session1,new
> URLName(mailHost));
> trans.connect(mailHost,mailPort,userName,password) ;
> System.out.println(trans.isConnected());
> trans.sendMessage(msg, msg.getAllRecipients());
> trans.close();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> ************************************************** ****************************


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pls help me when i sent mail, it vil sending twice instead of once ,am using java.mail,am sending my code.... shailajabtech@gmail.com Java 0 09-28-2006 06:38 AM
Sending Mail via System.Net.Mail problem =?Utf-8?B?T3Bh?= ASP .Net 3 01-31-2006 06:44 PM
Problem with System.Web.Mail.MailMessage and HTML mail =?Utf-8?B?TWlja2VCb3k=?= ASP .Net 1 06-21-2005 06:11 AM
Mail message size problem (System.Web.Mail) =?Utf-8?B?TXJGZXo=?= ASP .Net 0 03-14-2005 08:37 PM
Mail Question. Mail Problem James Messick Firefox 2 12-11-2003 09:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57