|
||
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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();
}
thanks sundar
|
|
||||
|
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:
Java Code
props.put("mail.smtp.host", host);
Java Code
props.put("mail.smtp.host", 25);
__________________
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.
|
|
|||
|
How do you access the Internet? Any proxy involved? Is the SMTP server outside the Intranet?
|
|
|||
|
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;
|
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |