Problem sending email using javamail in servlet

I try this code and make some changes of my own http://forums.sun.com/thread.jspa?threadID=695781.
When i run the program the confirmtaion shows that the mail has been sent, but when i check in my inbox there's no the message. I'm using gmail and need to authenticate the username and password. I guess the error caused in the servlet.
Here's the code for my servlet :
import java.io.*;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.internet.*;
import javax.mail.*;
public class ServletEx extends HttpServlet {
   public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws IOException, ServletException {
      System.out.println("____emailservlet.doPost");
      response.setContentType("text/plain");
      PrintWriter out = response.getWriter();
      System.out.println("______________________________");
      out.println();
      String to = request.getParameter("to");
      System.out.println("____________________________to" + to);
      String subject = request.getParameter("subject");
      String msg = request.getParameter("msg");
      // construct an instance of EmailSender
      System.out.println("servlet_to" + to);
      send(username, to, subject, msg);
      //send("[email protected]", to, subject, msg);
      out.println("mail sent....");
        String username = "[email protected]";
        String password = "my_password";
        String smtp = "smtp.gmail.com";
        String port = "587";
   public void send(String username, String to, String subject, String msg) {
        Properties props = new Properties();
        props.put("mail.smtp.user", username);
        props.put("mail.smtp.host", smtp);
        props.put("mail.smtp.port", port);
        props.put("mail.smtp.starttls.enable","true"); // just in case, but not currently necessary, oddly enough
        props.put("mail.smtp.auth", "true");
        //props.put("mail.smtp.debug", "true");
        props.put("mail.smtp.socketFactory.port", port);
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.socketFactory.fallback", "false");
        SecurityManager security = System.getSecurityManager();
        try
            Authenticator auth = new SMTPAuthenticator();
            Session session = Session.getInstance(props, auth);
            //session.setDebug(true);
            MimeMessage message = new MimeMessage(session);
            message.setText(msg);
            message.setSubject(subject);
            message.setFrom(new InternetAddress(username));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            Transport.send(message);
        catch (Exception mex)
            mex.printStackTrace();
   public class SMTPAuthenticator extends javax.mail.Authenticator {
        public PasswordAuthentication getPasswordAuthentication(String username, String password)
            return new PasswordAuthentication(username, password);
}Actually it's been a long time for me to develope this program, especially with the authenticate smtp. Any help would be very appreciated :)

Accordingly to your stackTrace, I think that you miss some utility jar from Geronimo app. server.
As you are using Application server that is J2EE compliant, so there is an own JavaMail implementation embeded and used by the Server. To fix this problem you have to find and add to your calsspath a jar-file that contains Base64EncoderStream.class

Similar Messages

  • TS2621 Problem sending emails using iphone 4

    I cannot send emails using my iphone 4.  All the mails can be received without any problem.  I don't have data plan and use wi-fi to access the internet.  Any suggestion is much appreciated.  Thanks

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    Setting up and troubleshooting Mail
    http://www.apple.com/support/ipad/assistant/mail/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Try this first - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.)
    Or this - Delete the account in Mail and then set it up again. Settings->Mail, Contacts, Calendars -> Accounts   Tap on the Account, then on the red button that says Remove Account.
     Cheers, Tom

  • Problems sending email using Edge

    OK, I have my own email server hosted with the company that hosts all of my websites (Cyberwurx)... They use port 25 for their outgoing mail server.
    I am able to receive email just fine using WIFI or Edge.
    However, when using Edge I can not seem to send email consistently. Every now and then it will work, but most often I get a "cannot connect to outgoing mail server" error when trying. As soon as I switch over to WIFI, the email sends perfectly.
    Any idea what is going on here? Is AT&T blocking port 25?

    Hi this thread may help. It is to do with the servers.
    Best regards
    Josh
    http://discussions.apple.com/thread.jspa?threadID=1232688&tstart=45

  • Problems sending email using outlook

    I constantly get the failure message 'Mail could not be sent' - The server for account " etc" returned the error "Service not available - too many authenticated connections' Your username / password or security settings may be incorrect. Would you like to try re-entering your password? Yes - No.
    When I respond with 'Yes' and then put in my passward, I get the reply Please enter your account ID and password for the SMTP server "mail.btinternet.com" I put in my password and tick the Remember this password in my keychain box but then everything simply repeats itself. I seem to have to go into my Outbox and then click on Send/Receive which then send the email.
    Is anyone else having this problem which started a couple of days ago and is sending me nuts!

    Outlook is a Microsoft product and not a lot of people here seem to use it. You will get the best and fastest answers to questions about Office:Mac and its components here:
    Office for Mac forums

  • Has anyone had problems sending emails using via (Road Runner) POP account?

    I cannot send any emails w/ the iPhone via Road Runner POP account.... I have tried everything. From Calling Time Warner to have my Password reset just incase I'm using the incorrect password, which in fact the settings menu for mail says the password for outgoing emails are optional.. I keep getting a message saying "my email was rejected by the server" Is anyone having this problem and if so please suggest any solutions.......
    Does anyone know how to set my mail app on my home computer to only forward the messages I want to my iPhone while moving all other junk emails to my Junk folder on my computer????

    Last I checked you could not access RoadRunner outgoing mail servers from outside of the RoadRunner network (i.e., the AT&T EDGE network). You can use cwmx.com as your outgoing mail server, with no ID or password, and that will work while you are on EDGE (but now when you are on WiFi).
    As for junk mail, that is the scourge of the internet. Many people have many solutions - I can share with you mine. I had all my email forwarded to a free GMail account. GMail has amazingly efficient SPAM filters, and it has cut down my spam 99%. You can configure your account on the iPhone using the "Other" shortuct in such a way that emails seem to come from your Roadrunner account. The added bonus is that the GMail outgoing server works on both EDGE and WiFi, so you dont have to worry about where you are at.

  • Problem sending email using Verizon email account in iPhone

    I am having the exact problem as in this archived thread:
    http://discussions.apple.com/thread.jspa?threadID=1266840
    I get an error:
    "Cannot Send Mail, the sender address was invalid."
    I am using an original iPhone with the latest software. I believe the problem started with the 2.0 or 2.1 update.
    Even before coming here, I had noticed that the authentication under advanced was set to "MD5 Challange-response" rather than "password".
    No matter how many times I change to "password" it doesn't stick, and of course the mail does not send.
    How can I get the correct setting to stick, or am I doing something else wrong?

    Thanks for the response. I see based on your response that I had not been changing the outgoing method of authentication.
    I found the outgoing mail authentication where you said it would be.
    I have the same problem though, I can change it from "MD5 Challange-response" to Password, but the change does not "stick".
    As soon as I leave the "page" and go back to it, the authentication has changed back to "MD5 Challange-response".
    I checked my friends iPhone 3g (I have an original with the latest software) who also has verizon, and his phone is set to password.
    On his smtp server page, authentication shows as "password" without even clicking on "authentication". My smtp page shows nothing next to authentication, I need to click on that to go to the next page to then see it has switched back to "MD5 Challange-response".
    Another oddity is his phone lists server port as 25, mine lists as 587. I tried changing mine to 25, but nothing changed, my authentication would not "stick" at password, and outgoing mail still did not send.
    Any help appreciated as sending e-mail from the phone is very important to me.

  • Problems sending email using javax.mail.*

    I need to send an email from an application I am working on. I am using the features of the javax.mail package to do so. In looking at the code I am unsure why this is not working. This is my first time using this package so it might be something silly I am missing so any of your thoughts are appreciated. The code is as follows:
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class EmailTester {
         public static void main(String[] args) {
              try {
                   //Set the smtp address
                   Properties props = new Properties();
                   props.put("mail.smtp.host", args[0] );
                   // get the default Session
                   Session session = Session.getDefaultInstance(props, null);
                   session.setDebug(true);
                   // create a message for this session
                   Message msg = new MimeMessage(session);
                   // set the from and to address
                   InternetAddress from =
                        new InternetAddress( args[1] );
                   InternetAddress[] to = new InternetAddress[1];
                   to[0] = new InternetAddress( args[2] );
                   msg.setFrom(from);
                   msg.setRecipients(Message.RecipientType.TO, to);
                   // set the subject and content type
                   msg.setSubject("subject");
                   msg.setContent("this is my test email", "text/plain");
                   // send the email
                   Transport.send(msg);
              catch (MessagingException me) {

    I have an EMail class that I use at:
    http://www.discoverteenergy.com/files/EMail.java
    Feel free to use it or compare against your code to see what is different.

  • Send email using JavaMail

    hi every body,
    i am newbie in JavaMail API
    my question is : can i send an email to an yahoo or hortmail account.
    if yes, how can i do it ?
    thanks

    Yes, you can do it.
    You need a mail server, either your own, or one owned by your
    company, or one owned by your ISP, or a public mail server on
    which you have an account.
    The JavaMail FAQ has the rest of the information.

  • Send mail with no sender address using Javamail

    I'm trying to send emails using javamail, it works fine but I would like to send emails with no sender address. When I don't set :
    message.setFrom(new InternetAddress("[email protected]"));
    or do just
    message.setFrom()
    I get my_user_name@my_machine_name as the sender address when i recieve the email.
    I understand the security problems about sending emails without sender but i need to automate the sending of confirmation messages that recievers can't answer to.
    Quentin.

    I get a lot of e-mail newsletters that say at the bottom "Please do not reply to this, nobody will read your reply". What's wrong with that? Set up an address and automatically purge any messages sent to it on a regular basis.
    Or if you want a different way to annoy people, use an address that doesn't exist on your server. Then people get a bounce message when they reply to it.
    You might also want to evaluate commonly-used spam filters and see if they filter out messages that don't have from-addresses. No point sending people messages if they get filtered out.

  • Problem with Thunderbird email: When I send email using a mailing list, with my email included in the list, the message shows up in my Sent list and others rece

    Problem with Thunderbird email:
    When I send email using a mailing list, with my email included in the list, the message shows up in my Sent list and others receive it but it does not come to my email Inbox. The same problem occurs when I send the email to the mailing list addresses individually. When I send a simple test message to myself, I do receive it in my Inbox. Can you help me??
    Bob Greenman

    Are you using either cc or bcc? Is googlemail involved? Some email providers suppress cc's and bcc's to oneself since you will have a copy in your Sent folder.

  • I am unable to send emails using mail from my btinternet and yahoo accounts similar problem to others with mobile me accounts on lion any suggestions?

    I am unable to send emails using mail from my btinternet and yahoo accounts similar problem to others with mobile me accounts on lion any suggestions?

    Do I need to delete all my email accounts and start again?

  • I am having problems sending emails when using apps. I dont receive any emails when I try to send documents such as pdf or pictures. I tried sending it to my other email account but I don't get any email. What is wrong?

    I am having problems sending emails when using apps. I dont receive any emails when I try to send documents such as pdf or pictures. I tried sending it to my other email account but I don't get any email. What is wrong?

    System Preferences > Network > your-connection-medium > (Assist me) > ( Diagnostics )
    This sometimes provides additional helpful information, sometimes not so much.

  • How to read emails using javamail

    hello friends
    well i am working on a project on phishing for that i had usinf javamail to read out the mails while i open my any email account while i working on the net .
    actually what i want is whenever i open my account my program could detect the mail and it will it work after that
    so can anyone please help me out in doing this means my first problem is how to get my program get linked with that so that everytime i opem my email account (not specific) i can use the message stuff written in that for my further use
    please help me guys i really need help
    please reply as soon as possible
    thanks

    i could not understand your problem exactly.
    if you mean you want to check the new messages count: you can simply used
    int newMessages = folder.getNewMessageCount();if you are reading mails first time using javamail.
    see http://itoday.wordpress.com/2007/04/08/sending-mail-using-javamail-apis/
    if you mean something else ... please let me know
    asif shahzad
    Edited by: asifsh7 on Jul 22, 2008 8:53 AM

  • Loss of sending email using WIFI

    As of this morning 8-20-08, after updating to 2.02, I no longer am able to send emails using my own wireless network. Previously this was no problem. Neither Fido or Apple have any idea of what I am talking about. Fido washed their hands as they do not support WIFI. How convenient, they sell the phone and charge for the service but do not support it. Videotron, my ISP, thinks the issue is my wireless router but I can send via gmail so that's out. I resovled the problem by configuring my accounts to use my gmail smtp server as a second option and now the spinning wheel is short lived and messages are sent.
    I'm sorry to say that I had fallen for all the hype about Apple but truth is they are but a Microsoft wannabe.
    Disinchanted

    So here's the wierd thing.
    I was having the same problems. Set up SMTP for Videotron when at home using relais.videotron.ca SMTP with no authenticationon port 25 & all was good in the world. However when I went out, bang. Nothing. Couldn't send a mail for love nor money.
    Thought aboutit & changed settings to use relais.videotron.ca SMTP, but this time using authentication of vltl** / password credentials with no SSL (Videotron doesn't use SSL) and again everything was fine. Of course, when I got home again, bang. Everything fell over & no more mail sending foe me!
    So I figure, when I'm at home I'm on my trusted network at port 25, I don't need authentication and all is good, but when I'm out i'm seen as potential SPAM by port 25 on videotron & get blocked.
    Tried using port 587 instead when for both home & mobile but had no luck either.
    Then a strange thing happened. I'd resolved to having to set up 2 SMTP servers on my iPhone & switching between the two based on where I was. Pain in the a**, but there's always a trade off for early adopter technology So I set up my primary SMTP to use port 25 with no authentication, and a secondary server to use the same relais.videotron.ca outgoing server, but this time WITH authentication using vltl** \ password credentials.
    After a walk to the shop when I'd been on my secondary SMTP server (successfully sending & recieving) I came home & inadvertantly forgot to swith back to my primary SMTP. Recieved a mail & then responded with no problem!
    Net result, I now have a permanently switced off primary server & a permanently switched on secondary server which uses relais.videotron.ca details with vltl** \ password authentication credentials active (like I did on my old silver iPhone) & all is good in the world, both at home & out mobile, both for sending & recieving!
    Will field test some more tomorrow but it may be a 2.0.2 bug where ther primary server details fcuk up whereas the secondary server details are stable.
    So long as it works, who cares!
    Jof

  • How can I send email using two different email address that both link back to my one exchange account on my Ipad mini

    How can I send email using two different email address that both link back to my one exchange account on my Ipad mini? 
    On my PC I simply have a master return email address and use a POP for the secondary address.  Both are through the one exchange account without a problem.  I need to be able to do the same on my Ipad.

    Ah, I should have made that clear.  My domain didn't come from google.  It was purchased at and is hosted at dreamhost, but I haven't used their email servers in years - I just route everything through gmail.  I actually have a bunch of domains (with websites).
    Gmail has an option that lets someone with custom domains send (and receive) email through gmail using the custom domain once Google confirms proper ownership of the domain (to prevent spammers and such).  Gmail has a setting for "send email as" which allows gmail to be sent using a custom domain as the sender.  I'm pretty sure Apple's old mobileme had this feature too, but I didn't use it.

Maybe you are looking for