Go Back   Java Programming Forums > Java Standard Edition Programming Help > Java SE APIs


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 26-05-2008, 06:05 AM
Junior Member
 

Join Date: May 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
sundarjothi is on a distinguished road
Default Java mail problem(working in intranet,but not working in iternet)

Hi everyone,

I have a little problem with my java mail coding.
While i was using java mail coding in local netwok(intranet) properly executing.
But i was used in internet, it is not working.
I told my problem(java mail is not working prperly) to my server maintainer(service provider).
They told "we loaded all mandatory jar files in Tomcat server please verify your coding"
And told " please check your smtp protocal" and wrote code
u shoud use smtp as 25

other things asp and php coding are not supported in java server ..
u should send mail coding through jsp
Please check once & let us know if any problems !
Please let us know the error URL / Path if you have any more problems, thanks

please refer my coding and tell what is wrong with coding

Java Code
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
//props.put("mail.debug", "true");
Session session = Session.getInstance(props, null);
//session.setDebug(debug);
 
try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
 
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);
 
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
 
// attach the file to the message
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
 
// create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
 
// add the Multipart to the message
msg.setContent(mp);
 
// set the Date: header
msg.setSentDate(new java.util.Date());
 
// send the message
Transport.send(msg);
flag=true;
 
 
}catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}
please reply immediately

thanks
sundar



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 02-06-2008, 09:50 AM
JavaPF's Avatar
mmm.. coffee
 
8 Highscores

Join Date: May 2008
Location: United Kingdom
Posts: 1,543
Thanks: 98
Thanked 92 Times in 85 Posts
JavaPF is someone you want to know!JavaPF is someone you want to know!JavaPF is someone you want to know!

I'm feeling Relaxed
Default Re: Java mail problem(working in intranet,but not working in iternet)

I can't really see anything wrong with this code although I am unable to test it. Have you got any further with it?

Quote:
u shoud use smtp as 25
Have you set:

Java Code
props.put("mail.smtp.host", host);
To the correct SMTP host and port? I think it should be:

Java Code
props.put("mail.smtp.host", 25);
Assuming that mail.smtp.host is your SMTP host.
__________________
Don't forget to add syntax highlighted code tags around your code: [highlight=Java] code here [/highlight]

Forum Tip: Add to peoples reputation () by clicking the button on their useful posts.
Reply With Quote
  #3 (permalink)  
Old 08-10-2008, 04:06 AM
Junior Member
 

Join Date: May 2008
Location: Canada
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
danielstoner is on a distinguished road
Default Re: Java mail problem(working in intranet,but not working in iternet)

How do you access the Internet? Any proxy involved? Is the SMTP server outside the Intranet?
__________________
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
Reply With Quote
  #4 (permalink)  
Old 25-01-2009, 05:17 AM
Junior Member
 

Join Date: Nov 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
arvind321 is on a distinguished road
Default Re: Java mail problem(working in intranet,but not working in iternet)

I have this simple SMTP program working - both intranet and internet.

See if this works for your needs.

Java Code
                   public void sendMail()
	{
		try
		{
    		Socket s = new Socket(this.getSmtpServer(), 25);
    		
    		InputStream inStream = s.getInputStream();
    		OutputStream outStream = s.getOutputStream();
    		
    		in = new Scanner(inStream);
    		out = new PrintWriter(outStream, true /* autoFlush */);
    		
    		String hostname = InetAddress.getLocalHost().getHostName();
    		
    		receive();
    		send("HELO " + hostname);
    		receive();
    		send("MAIL FROM: <" + this.getFrom() + ">");
    		receive();
    		
    		// Parse the Test Plan names which are comma seperated
    		String patternStr = ",";
    		String[] fields = this.getTo().split(patternStr);
    		for (String value : fields)
        		send("RCPT TO: <" + value + ">");
    		
    		receive();
    		send("DATA");
    		receive();
    		send("subject: " + this.getSubject());
    		send(this.getMessage());
    		send(".");
    		receive();
    		s.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static void receive() throws IOException
	{
		String line = in.nextLine();
		
	}
	
	public static void send (String s ) throws IOException
	{
		out.print(s.replaceAll("\n", "\r\n"));
		out.print("\r\n");
		out.flush();
	}
	
	private static Scanner in;
	private static PrintWriter out;
Reply With Quote
  #5 (permalink)  
Old 27-01-2009, 04:03 AM
Junior Member
 

Join Date: Dec 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
vigneswara is on a distinguished road
Post Re: Java mail problem(working in intranet,but not working in iternet)

please check ur smtp host and ur port number
why don't u use gmail host
imn my project i use gmail host
host name is gmail.com port is 465
if u are interested to see this code please click on the following link
paruchuri.vigneswara - Sending Mails using java
and put mail.jar file in ur lib directory or in the classpath

Last edited by vigneswara; 27-01-2009 at 04:04 AM. Reason: small spelling mistake
Reply With Quote
Reply

Thread Tools
Display Modes

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 On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending and Receiving mail using J2ME chals Mobile Applications 5 02-06-2009 02:59 PM
[SOLVED] Abstract problem in java using vista Uzual AWT / Java Swing 2 26-05-2009 04:23 PM
Java GUI problem - paintComponent? Richard_ AWT / Java Swing 2 01-05-2009 01:19 PM
[SOLVED] JAVA JList Problem antitru5t AWT / Java Swing 4 15-04-2009 08:09 PM
FileNotFoundError when working with xml files in windows ochieng File I/O & Other I/O Streams 1 14-11-2008 11:56 AM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 02:05 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.