aspose file tools*
The moose likes Servlets and the fly likes Problem during sending email using JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem during sending email using JSP" Watch "Problem during sending email using JSP" New topic
Author

Problem during sending email using JSP

aamir abbas
Greenhorn

Joined: May 04, 2001
Posts: 19
Hi,
i m trying to send mail using JSP. i have done it successfully when i use my companies mail server, and send an email to my company's email address. But when i was try to send email to my yahoo address (i.e. a_abbas77@yahoo.com) then i got javax.mail.SendFailedException : 550 5.7.1 unable to relay for a_abbas77@yahoo.com
Can somebody help me to solve this problem . . .
Thanks in advance . . .
Aamir
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi aamir,
i have done the same thing in my module.i think the code \below can help u.i have mad a class called mailer u can use the class.for using the class should download javamailapi,java activationframework in ur class path and continiue. the code is

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

public class mailer{

public mailer(String from,String to,String text1) {


boolean debug = true;
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", "ur smtp server ip address!!");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
try {
// create a message
MimeMessage msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

InternetAddress[] address = {new InternetAddress(to)};
InternetAddress[] address1 = {new InternetAddress();address1.parse("viky4u@yahoo.com,viky4u@yahoo.com")};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setRecipients(Message.RecipientType.BCC, address1);
msg.setSubject("Waltech Forum Message from "+ from );
msg.setSentDate(new Date());
msg.setText(text1);
// create and fill the first message part
//MimeBodyPart mbp1 = new MimeBodyPart();
//mbp1.setText(msgText1);
// create and fill the second message part
//MimeBodyPart mbp2 = new MimeBodyPart();
// Use setText(text, charset), to show it off !
//mbp2.setText(msgText2, "us-ascii");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
//mp.addBodyPart(mbp1);
//mp.addBodyPart(mbp2);
// add the Multipart to the message
//msg.setContent(mp);
// send the message
Transport.send(msg);
} catch (Exception mex) {
mex.printStackTrace();
Exception ex = null;
ex.printStackTrace();

}
}
}
reply back if u have any problem..this must work perfect.
bye,love
Vigneshk.c
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Don't want to be unpleasant but have you considered reading the forum before you post? This topic was last discussed here less than a day ago. And with a subject like "sending an email from jsp" it should not have been that hard to find.
- Peter
aamir abbas
Greenhorn

Joined: May 04, 2001
Posts: 19
Originally posted by KCVignesh:
hi aamir,
i have done the same thing in my module.i think the code \below can help u.i have mad a class called mailer u can use the class.for using the class should download javamailapi,java activationframework in ur class path and continiue. the code is

Hi Vignesh,
Thanks for ur reply. actually i have successfully send mail using my companies mail server (say "abc.ubitec.com"). It works fine but only with my company's account, i.e. when i send an email to my ubitec account (aamirabbas@ubitec.com). The problem is that when i try to send email to my yahoo account it fails. . . i think problem is with my mail server . . . can i use any other server ??? i also try to use yahoo's nomail.yahoo.com server (someone tell me abt that) but when i use nomail.yahoo.com as smtp host then UnknownHost Exception is generated . . . plz guide me abt which mail server can i use . . .???
Waiting for ur reply . . .
Aamir
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
Hi, do you use this code as a bean in a JSP page? But it does not look like a bean to me...
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Oh well. Perhaps it wasn't clear. Here goes.
Mail servers are generally happy to accept mail for users local to that server. But, with very rare and short-lived exceptions, they do not accept mail which would need to be transported (jargon: relayed) someplace else, except from a few privileged hosts.
The reason that they don't - and the reason that exceptions are short-lived - is spam. Spammers love relaying hosts to send their tens of thousands of e-mails. A third party relay allows them to hide their origin. Their ISP is unlikely to take action against them, since it is a third party which gets to bear all of the load, and some hours later all of the complaints. Many a naive systems administrator has learnt that lesson the hard way.
So that's your problem. You can forget about using an arbitrary mail host to relay your mail. It won't. You can stop trying the hosts people suggest to you. They won't work. You have to ask your company's systems administrator to allow their SMTP server(s) to relay for your machine, or register with an ISP or e-mail service provider. Full stop.
HTH
- Peter

[This message has been edited by Peter den Haan (edited May 05, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem during sending email using JSP