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.

Similar Messages

  • 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.

  • Problem sending emails with Mac Mail 1.3.11

    Desperately in need of help. I'm able to receive but not send email using Mac Mail. I keep getting an error message:
    "This message could not be delivered and will remain in your Outbox until it can be delivered.
    The sender address [email protected] was rejected by the server"
    I have already tried the following at the advice of AppleCare reps:-
    Have verified & repaired disk utilities & keychains
    Have reinstalled the operating system
    Have trashed the mail.plist file
    Have trashed the outbox.mbox file
    Getting quite frustrated now because we have a mac bookpro with identical mail settings and it is able to send and receive mail without any problems.Could it be the version of Mail I'm running ?
    I initially thought that the problem related to having switched to a new ISP but the fact that one of the mac's has no problem has led me to be less convinced of that idea.
    Any suggestions gratefully accepted.
    Many thanks

    I am having the same problem exactly. I can read e-mail, but get the same error message trying to send it. I can't use .Mac anymore--have to use alternate e-mail for the last month--since some time in October 2006.
    I haven't changed anything on my G4, haven't upgraded anything, and the problem started about the time .Mac reported some customers were unable to use Mail for a couple of days in October.
    I see nobody answered your post. Did you ever get your mail to work? I have repaired permissions, but I don't think it has anything to do with that.
    Thanks,
    iMama
    G4 Quicksilver 867Mhz 60GB   Mac OS X (10.3.8)   Maxtor 120GB internal; LaCie 150GB external HD

  • 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

  • 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

  • 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

  • How Do I Increase The Speed Of Sending Emails Using The Mail Service on my Mac Mini Server?

    Note: This is the first time I have set up a mail server.
    I have a Ruby on Rails application where I am currently sending approx. 240 individual emails with the potential of more being sent each week as more people add themselves to our mailing list.  I am sending them invidually in order to personalize the emails and to hopefully prevent my emails being falsely identified as spam.
    The GoDaddy email address I was using in my Rails application has a daily limit of sending 250 emails each day.  With our mailing list fastly approaching 250 I decided to set up an email address on my Mac Mini Server using Mountain Lion (OS X Server).  The email address was set up to be stored locally at the advice of Apple Enterprise Support.  This email address will not be used in an email program.  It will only be used in all my Rails applications.
    My emails send properly but take almost 10 seconds an email.  When I use the same software with GoDaddy's email address the emails take about eight minutes to send.  With the email address I created it takes about 41 minutes.  The difference seems to have to do with the sacl_check being done.  Here is an example of what I see for each email in mail.log.
    Mar 14 11:06:50 hostname.domain1.com postfix/qmgr[45322]: 4B2C5603D25: removed
    Mar 14 11:06:59 hostname.domain1.com postfix/smtpd[99464]: sacl_check: mbr_user_name_to_uuid([email protected]) failed: No such file or directory
    There is 9-10 seconds that elapses when the sacl_check.  If I subtract this difference the remaining time is almost the time that the GoDaddy email takes to send the same number of emails.
    The link below is a post about the sacl_check.  I was looking at the comments by powercore from Germany at the comments where settings in /etc/postfix/main.cf are discussed.
    https://discussions.apple.com/thread/3241121?start=0&tstart=0
    Will making these setting changes speed up the sending of the emails from my Mail Server or is there something else I can check?

    http://en.wikipedia.org/wiki/Intel_Quick_Sync_Video
    OS X [edit]
    Apple added Quick Sync support in OS X Mountain Lion for AirPlay Mirroring and QuickTime X.[9]

  • Can't send email using Windows Mail (Vista) through Anonymizer proxy server

    I have recently installed a new version of Anonymizer which I need for access to a particular forum, but when it is connected I cannot send email. The message I got from Anonymizer support is as follows:
    Anonymizer Universal blocks unencrypted mail port 25 to prevent abuse of our service by spammers. If you have an email address set up to use port 25, please contact your mail administrator to use an alternate port. We have found email providers prefer certain ports including 587 and 465. These ports generally require authentication and you may need to change your outgoing mail server to require authentication.
    I tried these port numbers but they also gave errors. Any suggestions will be appreciated.
    Solved!
    Go to Solution.

    I found the thread on port 587 and I followed the advice on the link for Outlook Express.
    http://www22.verizon.com/ResidentialHelp/HighSpeed​/Email/Setup+And+Use/QuestionsOne/124306.htm
    Windows Mail is slightly different but when I set the outgoing port to 587 without requiring authentication, and it seems to be working OK now. So I'll mark this as solved. This seems to be a major issue since November and it should be in the FAQs and easy to find with a search.

  • Cannot send email using mac mail and yahoo att

    I recently was hacked and changed my att yahoo password and security questions. I got a confirmation email about this but not about changing the password. I can receive mail, but not send any. All my settings in preferences seem to be correct. The TLS certificate is not check however, and I'm wondering if that has something to do with it. The port number has not been changed, nor the outgoing service address: which is:  smtp.att.yahoo.com: (followed by my email account name). I've had this email address for years and want to keep using it. apparently Yahoo has been having allot of problems over the last few days and I've found it hard to access their trouble shooting sites and log in page. Is there something I can do on my end to fix this? Thanks.

    Could be many things, we should start with this...
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)
    If perchance you can't find your install Disc, at least try it from the Safe Boot part onward.

  • 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.

  • Can't send email using Apple Mail with Verizon

    My Verizon settings in my Apple Mail program will not send mail. I am using my correct password and userid for authentication. I use outgoing.verizon.net server and port 587. Should I be using a different port setting?

    port 110 is the port number for the incoming (pop) mail server, port 25 is the port number for the outgoing (smtp) mail server. If they were insisting that you use port 110 for the outgoing (smtp) mail server, that is because the tech support rep with whom you spoke was not a very clueful person. These are established standard port numbers for those services.
    PS- should you have found anyone's post in this thread helpful to you, like Jim's, consider clicking the "helpful" or "solved" buttons in the header of said posts and if you don't click the "solved" button ("helpfuls" alone don't mark a thread as "answered"), then also consider marking this thread as "answered" for the benefit of others searching out a solution to a similar problem with their Verizon Mail configuration.

  • I am unable to send emails using apple mail, but can still receive

    A very odd situation this.  I have a couple of POP3 accounts and an Exchange server account.  All was going well until a few days ago when all my accounts stopped sending mail, but still continued to receive mail.  I have removed each account and restored it but this hasn't worked, the timer is constantly spinning against the 'Sent' header.  All these accounts work in their webmail version so I have to conclude the fault is with Apple Mail.  Can anyone help please?  Thanks.

    Troubleshooting Mail.
    http://support.apple.com/kb/ts3899

  • 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?

Maybe you are looking for

  • The file , edit, ect. will not open.

    I just downloaded firefox, i've used it before but not recently. It was working fine and this morning i booted up and it works for searches but none of the buttons work, they pop in then the menu doesn't come up. should i reinstall? i really like fir

  • Drill Down feature for pie chart in JSP

    Hi, I need to have drill down feature in my Pie Chart which is generated using JFreeChart package. The pie chart is generated dynamically basing upon the database values as inputs . Now on click of any one sector i have to show other bar graph. The b

  • Dates Determination in Rebate

    Hi ERP gurus, I'm getting troubles with rebate management. Here below an example I created a rebate agreement starting from first of january and ending at the end of September. Let's assume that today 5th of october  i create a credit memo request th

  • Inbox search not returning item count for certain category's entered...

    I suspect there's a BADI for this but at present the item count is not being displayed for two of the six category's that we have. In other words four of the Categories used do show the number of items returned, but two do not. Can anyone give me som

  • Opening .eml documents

    I get emails with .eml attachments which should use Power Point to open. However, I have not been able to open them with my OSX.4.11 which has Microsoft Ofc for Mac, & for which I downloaded Ofc Open XML Converter for Mac 1.0 this morning, from Apple