Sending Messages with JavaMail

I am new to JavaMail, and have a few questions. I am writing a Java application that only needs to send mail via an SMTP server.
1. Do I need the JAF (JavaBeans Activation Framework) if I only want to send mail?
2. I seem to be stuck at instantiating the Session. I am using the following:
Properties props = new Properties();
props.put("mail.smtp.host", "mySMTPhost");
Session session = Session.getDefaultInstance(props, null);
If I wrap the Session line in a try/catch, nothing gets piped out to my log file. When I comment out this line, my System.out.println()'s work.
3. Could this be because I am not using the correct Exception Type?
Any help would be greatly appreciated.

how to give arguments for the msgshow demo program.
i'am using imate mail server.i have email account in
yahoo.what host,protocol,port numbers must be gn.
my email id: [email protected]

Similar Messages

  • How to send a message with javamail api

    Hi, anybody can tell me how i do to send a message with javamail?
    Thanks.
    Daniele.

    [rossifumi80],
    Here's a simple JavaMail application SendMessage.java that will connect a SMTP host and send a mail message out:
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class SendMessage {
      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);
    }HTH.
    Allen Lai
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/

  • I Can't send a message with JavaMail

    I can't send mail with JavaMail. I Try send a e-mail, for example, to: [email protected], from: [email protected], my smtp: smtp.alunos.ufu.br, but when i try it, i received a message the e-mail [email protected] not in server smtp.alunos.ufu.br.
    I don't anderstend what happen. I need the alunos.ufu.br send my message to [email protected]
    Somebody can help me ?????

    I think the problem is that your smtp server smtp.alunos.ufu.br is not relaying to addresses not local to itself. Please post the exact stack trace. There is some 500 level error being returned by the server that will tell you exactly what is happening.

  • Problem with sending message with excel attachment

    hi,
           i m using sap b1 2005b  i send message with excel attachment to sap user but message is reached to destination but attchment cannot send .ot shows an internal error pls help me.
    reagrds,
    vishal

    Vishal,
    Couple of questions. 
    How are you sending this message.  Is it a message that you create and send Internally with an attachment.
    As you reply me, please also check if the <b>Attachments folder</b> has been set under <b>Administration > System Initialization > General Settings.....Path Tab</b>
    SBO tries to copy the attachment from the location you select to the Path defined for Attachments.
    Let me know
    Suda

  • The XI does not send messages with correct IDOC structure

    SAP XI 3.0 sends to ECC IDOC HRMD_A07 
    The XI does not send messages with correct IDOC structure.
    In XI Design, Software Component RHEVOLU, I’ve imported the Objects
    HRMD_A.HRMD_A07 from SAP ECC; In Tools -> Export Reduced XSD, I saved
    HRMD_A.HRMD_A07.xsd in Namespace http://suezambiental.com.br/HR . At
    Message Mapping -> mmAdmissao, in Imported Message -> Import XML or
    XSD, I imported the reduced Idoc file generated above, mapping source
    fields to target fields.
    The IDOC sent from XI to ECC has this structure (template: 22122)
    E1PLOGI
    E1PORIG
    E1PITYP
    E1P0000
    E1P0001
    E1P0002
    Status 53 -HR: ALE inbound processing for HR master data
    But does not update HR Master data.
    The structure expected in ECC side (template: 20376) is:
    E1PLOGI
    E1PORIG
    E1PITYP
    E1P0000
    E1PITYP
    E1P0001
    E1PITYP
    E1P0002
    Status 53 -HR: ALE inbound processing for HR master data
    By using WE19 transaction, this structure was changed manually; so, the
    HR Master data was updated.
    Witch kind of customizing or correction could be made in XI, to send
    the correct structure to ECC?
    Best Regards
    Claudio

    Hi Claudio,
    In your case, there are perhaps two causes:
    1. perhaps when you have import the idoc, for a strange reason, a bad metadata was created by XI. You can clean this one in tcode <b>IDX2</b> (Idoc metadata cache).
    2. but it's also probably an error in your Message Mapping. Have you correctly manage segment E1PITYP?
    Regards
    Mickael

  • TS3276 I can't send messages with mail 6.0 of mountain lion, because I can't desactivate the option SSL (Secure sockets Layers); it is locked

    I can't send messages with mail 6.0 of mountain lion, because I can't desactivate the option SSL (Secure sockets Layers); it is locked

    Hi, i am having the same problem. this is what i have noticed.
    I have 2 x imac's and 2 x macbook air's
    i upgraded the 2 macbook air's and 1 of the imac's to Mountain Lion, all these have problems acessing sites that require you to login .
    the one remaining imac is still running lion and works perfect.
    i am using a dlink router with DD-WRT firmware, i tested teathering from my iphone and i can log into websites fine using the newly upgraded mac's.
    It's not a wireless issue as my imac is using an ethernet connection.
    is there a compatibility issue with some routers.

  • Can't send messages with old .mac/me aliases

    Hi, I'm using iCloud on the web because I have an old Powerbook as my primary device.  I specifically recall that Apple said that I can continue to use my .mac and .me aliases.  This is incredibly important since my business is tied to a particular .mac e-mail alias that I've had since, well, dotmac was around.
    It looks like I can receive messages with at least one of these aliases, but I cannot send messages with the alias.  The alias does not exist in the alias list pull down menu.  I tried adding the alias, but was told I already have too many.  Three?  Very frustrating!  Anybody know what's going on or how to fix it?  Thanks!
    -Jen

    IE11 is the most recent update.
    Try to reset all Skype settings.
    Quit Skype or use Windows Task Manager to kill any Skype.exe process. Go to Windows Start and in the Search/Run box type %appdata% and then press Enter or click the OK button. The Windows File Explorer will pop up. There locate a folder named “Skype”. Rename this folder to something different, e.g. Skype_old.
    Next go to Windows Start and in the Search/Run box type %temp%\skype and then press Enter or click the OK button. Delete the DbTemp folder.
    Restart Skype.
    N.B. If needed, you will still be able to re-establish your call and chat history. All data is still saved in the Skype_old folder.

  • Please help! I can't send messages with my IPod 5!

    I can't send messages with my iPod 5th gen. If anyone can help thank you!!!

    I just realized I don't have Lion, but I still have this problem with my email.

  • Sending messages with ipad impossible:user name or password incorrect

    Can't send messages with my IPAD.
    I'm tell that " Username or password for smtp:[email protected]@smtp.live.com is incorrect
    I need a clue
    Thanks

    Hello mipage,
    For that error you would need to make sure that the password is correct in Settings > Mail, Contacts, Calendars and look at the outgoing server settings. If you are unsure of what it should be, then the easiest way is to remove the email account and add it back in to add the correct settings. For more information, take a look at the article below 
    Get help with Mail on iPhone, iPad, and iPod touch
    https://support.apple.com/en-us/TS3899
    Regards,
    -Norm G. 

  • Can't send message with photo

    Can't send message with photo.

    Does this relate in any way to the three other threads you have going?

  • Is there an option to send messages with an added emoticon?, is there an option to send messages with an added emoticon?

    Is there an option to send messages with an emoticon?

    there is an application name emoji this is the link for it
    http://itunes.apple.com/us/app/emoji-free/id332509635?mt=8
    download this and install it after that open the app it will automatically install the emoticon keyboard for you and will give you a step by step guide for it

  • Javamail to send message with a custom messageclass to outook exchange

    Hello,
    I developed a microsoft outlook addin which added a custom message class to our outlook exchange. Now if a user sends a message of type "IPM.Note.OurCustomForm"; the recipient gets our custom addin when the message is received. My question is, is there any way to use JavaMail to send a message from our server, which is all in Java, which the Microsoft Office exchange will pick up as the "IPM.Note.OurCustomForm"; message class and display my addin.
    Some example code, or reference to similar problems would be appreciated, I have not programmed in Java since I graduated many a years ago :). Also, I was hoping to do this without using third party software (unless it is free), but I would none the less appreciate information about them too.
    Thanks much,

    I know nothing about Exchange, so all I can give you is a general approach to
    solving this problem. Remember that Exchange is full of Microsoft proprietary
    features that are not defined by any standard or specification.
    You need to learn how to construct a MIME format message that is equivalent
    to the new Exchange-proprietary message you created. One way to do that would
    be to use JavaMail (or some other non-Outlook email client) to read a message of
    that type from Exchange and examine the MIME structure of that message. That
    should give you enough information to construct a MIME message using JavaMail
    that has the same structure (MIME types, headers, etc.).
    The second part is constructing the actual content of the message. Since you
    created the new custom message class, maybe you already know how to do that.
    But if you used a tool to do that you might not understand the raw format of that
    message, in which case you may need to reverse engineer the format by reading
    sample MIME messages in that format.
    Does that help?

  • Is there any problem to use multiple threads to send email with JavaMail

    Dear all,
    I am using JavaMail 1.3.2 to send emails with SMTP, it works very well for a long time.
    But one day, I found that the email service hanged and I could never send email again until I restart the tomcat. I found that the reason was a deadlock had been created, the required resource for sending email had not been released.
    I guess the error is due to multiple threads are sending email at the same time. I made a test to create seperate thread for sending each email. After few days, I found this deadlock happened again. So, my question is: Can I use JavaMail with multiple threads? If not, I may need to sychronized all the thread that using JavaMail. I would like to make sure this is the reason for causing the deadlock problem.
    Here is part of my code for using JavaMail:
    transport = session.getTransport("smtp");
    transport.connect(email_host, smtp_user, smtp_pass);
    message.saveChanges();
    transport.sendMessage(message,message.getAllRecipients());
    which is very standard call, and it worked well for a long time.
    Here is part for my thread dump on tomcat:
    (Thread-339)
    - waiting to lock <0x5447c180> (a sun.nio.cs.StandardCharsets)
    (Thread-342)
    - locked <0x5447c180> (a sun.nio.cs.StandardCharsets)
    It seems that these happened after call the method transport.sendMessage() or message.updateChanges()
    , and the underlying implementation may require the JRE StandardCharsets object. But the object had been locked and never be released. So, the sendMessage() or updateChanges() can't be completed.
    Please give me some helps if you have any idea about it.
    Thanks very much!
    Sirius

    Note that the Nightly build gets updated daily (and sometimes more than once in case of a respin) and it is always possible that something goes wrong and it doesn't work properly, so be prepared for issues if you decide to stay with the Nightly build and make sure to have the current release with its own profile installed as well in case of problems.
    See also:
    * http://kb.mozillazine.org/Testing_pre-release_versions
    *http://kb.mozillazine.org/Creating_a_new_Firefox_profile_on_Windows
    *http://kb.mozillazine.org/Shortcut_to_a_specific_profile
    *http://kb.mozillazine.org/Using_multiple_profiles_-_Firefox

  • Sending � signs with JavaMail

    Hi chaps,
    At our company we use the JavaMail API through JNI to send emails externally to customers.
    Recently the business has decided that it would be nice to send pound (�) through, however it's not going to plan.
    Normally the messages are encoded in 7-bit which would seem to exclude the � (163), however it seems that it is first converted to a (=80, hex with no ascii correlation) and then to a Euro symbol.
    I've tried setting the "allow8bitmime" property in order to enable the SMTP service to support 8-bit encoding, but it's not working AND Microsoft say that our Exchange (v5.5) doesn't support 8-bit MIME types. The odd thing is that sending external emails via Exchange supports the � with no problems and is read in the mail reader as 8-bit encoded (!).
    Has anybody had any experience with issues like this ? Any reply appreciated.
    Thanks
    Ammonite

    Ammonite,
    I am working on a similar problem.. Did you say your
    email gets translated and prints the Euro symbol... I
    actually need out email to print Both the pound and
    the Euro and it does niether right now.. The current implementation I am working on will display a Euro instead of a pound, although this isn't by design. The message is encoded using "Quoted-Printable" and substitutes the pound for a =80 character. How this maps to a Euro is unknown to me :(
    In standard ascii the pound is outside the standard 7-bit encoding range (163) and featured in the Extended Set on the platform we use. I'm not sure about the Euro. The Iso-8859-1 charset which SH provided supports the pound in "Quoted-Printable" encoding, but this hasn't been well received by JavaMail MIME objects that I have tried.
    I haven't managed any sort of 8-bit encoding with JavaMail as yet, due to supposed lack of support in Exchange 5.5 and lack of response to the "allow8bitmime" property.
    does anyone know is using MimeMessage limit the
    message to ASCII characters only and does that rule
    out the Euro and the Pound symbol/
    It shoudn't rule them out, but I'm starting to believe that MimeMessages are necessarily helping things here :)

  • Problem Sending attachments with JavaMail API

    Hi,
    I am able to succesfully able to send the attachment but the body message is not going with it. If i dont send the attachment then the email body goes properly. i can't understand what the problem is . please help.
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    import com.sun.mail.smtp.SMTPMessage;
    public class Emailer
         String emailSubject = null;
         String emailBody = null;
        String smtphost = null;
         String ccAddr = null;
         String file = "C:\\trainee\\eclipse_lg.gif";
         Vector vecToAddr = null;
         Vector vecCCAddr = null;
         Address fromAddr = null;
      public Emailer(Hashtable hashConfigParam) throws Exception
            smtphost = (String)hashConfigParam.get("host");
            ccAddr = (String)hashConfigParam.get("ccAddr");
            vecToAddr = new Vector();
            vecCCAddr = new Vector();
      public Boolean setFromAddr(String fromEmailAddr)
              try
                   fromAddr = new InternetAddress (fromEmailAddr);
                   //if(true)
                   //throw new IOException();
              catch (Exception e)
                   return null;
         return new Boolean(true);
      public Boolean setToAddr(String toEmailAddr)
              try
                   for(int j=0; j< vecToAddr.size();j++)
                        if(((String)vecToAddr.get(j)).equals(toEmailAddr))
                             return new Boolean(false);
                   vecToAddr.add(toEmailAddr);
                   //if(true)
                   //throw new IOException();
              catch (Exception e)
                   return null;
                   return new Boolean(true);     
         public Boolean setCCAddr(String ccEmailAddr)
              try
                   for(int j=0; j< vecCCAddr.size();j++)
                        if(((String)vecCCAddr.get(j)).equals(ccEmailAddr) && ((String)vecCCAddr.get(j)).equals(ccAddr))
                             return new Boolean(false);
                   vecCCAddr.add(ccEmailAddr);
                   vecCCAddr.add(ccAddr);
                   //if(true)
                   //throw new IOException();
              catch (Exception e)
                   //System.out.println(e.getClass().getName());
                   return null;
              return new Boolean(true);               
         public Boolean setEmailSubject(String subject)
              try
                   emailSubject = subject;
                   if(emailSubject.equals(null))
                        return new Boolean(false);
                   else
                        return new Boolean(true);
              catch (Exception e)
                   return null;
              //return new Boolean(false);
         public Boolean setEmailBody(String body)
              try
                   emailBody = body;
                   if(emailBody.equals(""))
                        return new Boolean(false);
                   else
                        return new Boolean(true);
              catch (Exception e)
                   return null;
              //return new Boolean(false);
      public void sendEmail()
           try
                Properties eMailConfigProps = null;
                eMailConfigProps = System.getProperties();
                eMailConfigProps.put("mail.smtp.host", smtphost);
                Session session = Session.getInstance(eMailConfigProps, null);
                MimeMessage message = new MimeMessage(session);
                   try
                     message.setFrom(fromAddr);
                      for(int i=0; i< vecToAddr.size(); i++)
                         message.addRecipient(Message.RecipientType.TO,new InternetAddress((String)vecToAddr.get(i)));
                         for(int i=0; i< vecCCAddr.size(); i++)
                          message.addRecipient(Message.RecipientType.CC,new InternetAddress((String)vecCCAddr.get(i)));
                      message.setSubject(emailSubject);
                      //message.setText(emailBody);
                       BodyPart messageBodyPart = new MimeBodyPart();
                        messageBodyPart.setText(emailBody);
                        Multipart multipart = new MimeMultipart();
                        DataSource source = new FileDataSource(file);
                        messageBodyPart.setDataHandler(new DataHandler(source));
                        messageBodyPart.setFileName(file);
                        multipart.addBodyPart(messageBodyPart);
                        message.setContent(multipart);
                        Transport.send(message);
                   catch (SendFailedException ex)
                     ex.printStackTrace();
                   catch (MessagingException ex)
                     System.err.println("Exception. " + ex);
           catch (Exception e)
                System.out.println(e.toString());
    public static void main(String args[])
          Hashtable hash = new Hashtable();
          hash.put("host","213.312.230.211");
          hash.put("ccAddr","[email protected]");
         try
               Emailer objEmailer = new Emailer(hash);
              Boolean fromFlag = objEmailer.setFromAddr("[email protected]");
              String toAddresses = "[email protected]";
              String ccAddresses = "[email protected]";
              Boolean toFlag = objEmailer.setToAddr(toAddresses);
              Boolean ccFlag = objEmailer.setCCAddr(ccAddresses);
              Boolean subjectFlag  = objEmailer.setEmailSubject("Emailer.java");
              Boolean bodyFlag = objEmailer.setEmailBody("blah blah blahblha ");
              if((fromFlag.toString()).equals("true") && (toFlag.toString()).equals("true") && (bodyFlag.toString()).equals("true"))
                   objEmailer.sendEmail();
         catch(AddressException e)
              e.printStackTrace();
         catch(Exception e)
              e.printStackTrace();

    i.e example :
    u can do it in this way
    MimeBodyPart messageBody = new MimeBodyPart();
    messageBody.setText("your message body goes here");
    // attaching file i.e make separate object of body part
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(filePath);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(fileName);
    multipart.addBodyPart(messageBody);
    multipart.addBodyPart(messageBodyPart);
    mimemessage.setContent(multipart);
    Transport.send(mimemessage);

Maybe you are looking for

  • 24" imac video anomaly..anyone know?

    Hi all, I just recently purchased a customer order 24" imac with the bigger HD, Vram and sys. ram and it is sooooo nice. But later that day (after about 5 hours of use) as I was setting up all my preferences, I noticed that the screen kinda flickered

  • Error on deleting a record

    Hi, I got an ArrayIndexOutOfBOundException when I try to delete a record from table. Caused by: oracle.jbo.domain.GenericDomainException: JBO-25028: Domain object type Number.bigDecimalValue cannot be created: java.lang.ArrayIndexOutOfBoundsException

  • "Out of memory" message when trying to copy audio configuration between songs

    Hello again, Any suggestion welcome about how to do paste an audio configuration successfully in 9.1.8. Here both the source and target songs are quite light stuff, 20 tracks, not much automation, never more than 3 inserts. The computer has 16 GB of

  • Form included in JSF Fragments doesn't work

    Hi there i have a simple form placed in JSF page fragment, the fragment is included in several pages. It renders , but the button action doesn't do what it is supposed to do. <?xml version="1.0" encoding="UTF-8"?> <!--     Document   : AddAdvertForm

  • How to download Flash Builder beta on a bad connection?

    I'm on a slow, unstable connection and 1gb is pretty hard to get without stalling and resuming multiple times, but resuming doesn't seem to work in labs for some reason - maybe my session times out? I usually use Free Download Manager to handle big f