File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Send Mail problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Send Mail problem" Watch "Send Mail problem" New topic
Author

Send Mail problem

Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi all,
I am trying to send an email from my servlet. For that I am using JavaMail API. I do have all the classpath settings.
I am using Apache JServ.
This is the wrapper classpath settings for my JServ.
wrapper.classpath=C:\javamail-1.2\mail.jar;C:\javamail-1.2\mailapi.jar;C:\javamail-1.2\smtp.jar;C:\javamail-1.2\pop3.jar;
wrapper.classpath=C:\jaf-1.0.1\activation.jar;
For more safety I added all the jar files in the classpath.
Now I am sending a mail.
But no mail is being sent.\
The code that I am using is this : ( which is posted here in the Saloon)
public class SendMail2 extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)
{
try
{
res.setContentType("text/html");
String from = "";
String to = "";
String subject = "the subject u wanna send ";
String cc="";
String bcc="";
String text="the matter that u wanna send ";
java.util.Properties prop = System.getProperties();
prop.put("mail.smtp.host","mail.yahoo.com");
getServletContext().log("props"+prop);
Session ses = Session.getInstance(prop,null);
MimeMessage message = new MimeMessage(ses);
getServletContext().log("mimemessage"+message);
try
{
Address fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
message.setSubject(subject);
Address[] toAddress = InternetAddress.parse(to);
Address[] cc_address=InternetAddress.parse(cc);
Address[] bcc_address=InternetAddress.parse(bcc);
message.setRecipients(Message.RecipientType.TO,toAddress);
message.setRecipients(Message.RecipientType.CC,cc_address);
message.setRecipients(Message.RecipientType.BCC,bcc_address);
message.setSentDate(new java.util.Date());
message.setText(text);
PrintWriter out = res.getWriter();
out.println("message sent");
getServletContext().log("mimemessage"+message.text);
Transport.send(message);
}
catch(Exception e)
{
System.out.println("Problem " + e);
}
}
catch(Exception e)
{
}
}
};

Any idea of how will I correct this problem ?
Thanks,
Maya
Dorj Galaa
Ranch Hand

Joined: May 29, 2001
Posts: 113
prop.put("mail.smtp.host","smtp.mail.yahoo.com");


Senior software engineer
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi Dorj,
Still the mail is not coming. I don't know how will I correct this problem.
Can u or anyone else please help me.
Thanks,
Maya
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
I used the simple program
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String from = args[1];
String to = args[2];
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress(from));
// Set the to address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail");
// Send message
Transport.send(message);
}
}
and used
smtp.mail.yahoo.com, my yahoo address my hotmail id
It gives the following error :
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 521 yahoo.com closing transmission channe
l. You must be pop-authenticated before you can use this smtp server, and you m
ust use your yahoo mail address for the Sender/From field.
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at MailExample.main(MailExample.java:37)
Please help.....
Dorj Galaa
Ranch Hand

Joined: May 29, 2001
Posts: 113
why u not use your smtp mail server?
I think if you have yahoo account choose pop3 access option
Dorj Galaa
Ranch Hand

Joined: May 29, 2001
Posts: 113
can't use smtp.mail.yahoo.com server send mail
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
HI Dorj,
I was trying the example using yahoo smtp server. I got it working yesterday once I set up the pop access for my yahoo account.
In the case of my smtp server, since we are behind a firewall, am I able to use it ?
for example, if my smtp server is dd.scs.com what all set uos do I need to do for it to send a mail to an outside person in s different firm ?
Thanks,
Maya
Dorj Galaa
Ranch Hand

Joined: May 29, 2001
Posts: 113
if your firewall not filtered your IP you can't use your smtp server send mail. on firewall can open your IP and only from your IP access to smtp mail server. try open this option.
Dorj Galaa
Ranch Hand

Joined: May 29, 2001
Posts: 113
if you know Java Cryptography can you help me?
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Ho Dorj,
I haven't done Java cryptography, but can try if I can.
Thanks,
Maya
 
 
subject: Send Mail problem