• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Send Mail problem

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
prop.put("mail.smtp.host","smtp.mail.yahoo.com");
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why u not use your smtp mail server?
I think if you have yahoo account choose pop3 access option
 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can't use smtp.mail.yahoo.com server send mail
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you know Java Cryptography can you help me?
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ho Dorj,
I haven't done Java cryptography, but can try if I can.
Thanks,
Maya
 
You can't expect to wield supreme executive power just because
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic