Javax.mail question

I am working on a project and encounter a problem when I try to use javax.mail package to send email. For some season, I have to use a name without the domain name as the sender (such as Sender rather than Sender @sun.com). I got MessagingException called 501 Syntax error, mail from: <Sender>" unrecognized or missing. When I add the domain name in (subtitute Sender with [email protected]), the program worked. My mail server admin told me there is no restriction on the mail server to regulate the sender's name (also it allows relay messaging). I don't know if she is right because I don't know much about mail server. Also, I figured out that I have no problem with InternetAddress("Sender"). The only thing might have problem is Message.send().
Anybody has a thought?
Thanks in advance.

In an effort to reduce the amount of spam hitting, mail relays are configured to refuse to accept pieces of email whose SMTP envelope's From header isn't resolvable
If the header in the form of user@host instead of a globally-resolvable [email protected], a bounce message would return to your user with an error message like:
451 <user@mailhost>... Domain does not resolve
This means that your mail relay is identifying itself as mailhost rather than mailhost.your.domain.
How this is fixed will depend on your mail transfer agent and your own DNS. Given that this is very site-specific, I can't provide any more help about host configuration.
Certain mail user agents (MUAs) like Netscape, Eudora, etc., that want to use an ``SMTP host'' to deliver outgoing mail will write their own SMTP envelope. They'll do this by taking the value that the user provided as their email address (which will appear in the message's From: header and using it in the SMTP envelope From header. A mail transfer agent, configured to use the user's real email address, should be able to send mail to without problem.

Similar Messages

  • Quick javax.mail Question

    Can anyone tell me if javax.mail is the same as JavaMail API 1.2, if not do you know of a url of where I can download it.
    Thanks everyone

    Yes, it's the same.

  • Getting javax.mail.AuthenticationFailedException: EOF on socket. Need Help

    I am trying to get hotmail emails and store in Oracle 10g database.
    When I am executing receivemail procedure from Oracle 10g database. I am getting following error.
    connect to ESIMSCO_UTIL_OWNER
    SQL> set serveroutput on
    SQL>
    SQL> Declare
    2 v_error_msg varchar2(10000);
    3 Begin
    4 v_error_msg:=receivemail('pop3.live.com', '<My email address>@hotmail.com', '<My email password>');
    5 dbms_output.put_line(v_error_msg);
    6 End;
    7 /
    javax.mail.AuthenticationFailedException: EOF on socket
    PL/SQL procedure successfully completed.
    SQL>
    I did following steps, but still I am getting this error. Can somebady help me to solve this problem.
    connect sys/<password>@esimsco as sysdba
    connect to sys
    SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 30 16:02:04 2012
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> begin
    1 dbms_java.grant_permission( 'ESIMSCO_UTIL_OWNER', 'SYS:java.util.PropertyPermission', '*', 'read,write' );
    2 commit;
    3 end;
    4 /
    PL/SQL procedure successfully completed.
    SQL> begin
    2 dbms_java.grant_permission(
    3 grantee => 'ESIMSCO_UTIL_OWNER',
    4 permission_type => 'SYS:java.net.SocketPermission',
    5 permission_name => '*',
    6 permission_action => 'connect,resolve'
    7 );
    8 end;
    9 /
    PL/SQL procedure successfully completed.
    SQL> begin
    2 dbms_java.grant_permission(
    3 grantee => 'ESIMSCO_UTIL_OWNER',
    4 permission_type => 'SYS:java.util.PropertyPermission',
    5 permission_name => '*',
    6 permission_action => 'read,write'
    7 );
    8 end;
    9 /
    PL/SQL procedure successfully completed.
    SQL> commit;
    Commit complete.
    SQL>
    Then I connect ESIMSCO_UTIL_OWNER.
    connect to ESIMSCO_UTIL_OWNER
    Create 2 tables.
    create table attachment(
    at_file varchar2(500),
    at_mimetype varchar2(500),
    at_attachment blob
    create table email (
    em_incident integer,
    em_from varchar2(1000),
    em_subject varchar2(1000),
    em_body nclob
    Then Create java source named receivemail.
    create or replace and compile java source named receivemail as
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import java.io.*;
    import java.sql.*;
    import sqlj.runtime.*;
    import oracle.sql.BLOB;
    public class ReceiveMail
    static void getAttachments(Message message, int incidentNo)
    throws MessagingException, IOException, SQLException {
    //String attachments = "";
    Object content = message.getContent();
    if (content instanceof Multipart)
    // -- Multi part message which may contain attachment
    Multipart multipart = (Multipart)message.getContent();
    // -- Loop through all parts of the message
    for (int i=0, n=multipart.getCount(); i<n; i++) {
    Part part = multipart.getBodyPart(i);
    String disposition = part.getDisposition();
    if ((disposition != null) &&(disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))) {
    //-- This part is a file attachment
    String fileName = incidentNo+"_"+part.getFileName().replace(' ','_');
    System.out.println("FILE: " + fileName);
    String contentType = part.getContentType();
    String mimeType = contentType.substring(0,contentType.indexOf(";"));
    System.out.println("FILETYPE: " + mimeType);
    InputStream is = part.getInputStream();
    // -- To work with a BLOB column you have to insert a record
    // -- with an emptly BLOB first.
    #sql { insert into attachment(at_file, at_mimetype, at_attachment)
    values (:fileName, :mimeType, empty_blob()) };
    // -- Retrieve the BLOB
    BLOB attachment = null;
    #sql { select at_attachment into :attachment
    from attachment where at_file = :fileName };
    // -- Fill the BLOB
    OutputStream os = attachment.getBinaryOutputStream();
    int j;
    while ((j = is.read()) != -1) {
    os.write(j);
    is.close();
    os.close();
    // -- Set the BLOB by updating the record
    #sql { update attachment set at_attachment = :attachment
    where at_file = :fileName };
    static String getPlainTextBody(Message message)
    throws MessagingException, IOException
    Object content = message.getContent();
    if (message.isMimeType("text/plain")) {
    // -- Message has plain text body only
    System.out.println("SIMPLE TEXT");
    return (String) content;
    } else if (message.isMimeType("multipart/*")) {
    // -- Message is multipart. Loop through the message parts to retrieve
    // -- the body.
    Multipart mp = (Multipart) message.getContent();
    int numParts = mp.getCount();
    System.out.println("MULTIPART: "+numParts);
    for (int i = 0; i < numParts; ++i) {
    System.out.println("PART: "+mp.getBodyPart(i).getContentType());
    if (mp.getBodyPart(i).isMimeType("text/plain")) {
    // -- Return the plain text body
    return (String) mp.getBodyPart(i).getContent();
    } else if (mp.getBodyPart(i).isMimeType("multipart/*")) {
    // -- Body is also multipart (both plain text and html).
    // -- Loop through the body parts to retrieve plain text part.
    MimeMultipart mmp = (MimeMultipart) mp.getBodyPart(i).getContent();
    int numBodyParts = mmp.getCount();
    System.out.println("MULTIBODYPART: "+numBodyParts);
    for (int j = 0; j < numBodyParts; ++j) {
    System.out.println("BODYPART: "+mmp.getBodyPart(j).getContentType());
    if (mmp.getBodyPart(j).isMimeType("text/plain")) {
    // -- Return the plain text body
    return (String) mmp.getBodyPart(j).getContent();
    return "";
    } else {
    System.out.println("UNKNOWN: "+message.getContentType());
    return "";
    static void saveMessage(Message message)
    throws MessagingException, IOException, SQLException
    //String body = "";
    int incidentNo;
    // -- Get a new incident number
    #sql { select seq_incident.nextval into :incidentNo from dual };
    // -- Get the header information
    String from = ((InternetAddress)message.getFrom()[0]).getAddress();
    System.out.println("FROM: "+ from);
    String subject = message.getSubject();
    System.out.println("SUBJECT: "+subject);
    // -- Retrieve the plain text body
    String body = getPlainTextBody(message);
    // -- Store the message in the email table
    #sql { insert into email (em_incident, em_from, em_subject, em_body)
    values (:incidentNo, :from, :subject, :body) };
    // -- Retrieve the attachments
    getAttachments(message, incidentNo);
    #sql { commit };
    // -- Mark message for deletion
    // message.setFlag(Flags.Flag.DELETED, true);
    public static String Receive(String POP3Server, String usr, String pwd)
    Store store = null;
    Folder folder = null;
    try
    // -- Get hold of the default session --
    Properties props = System.getProperties();
    props.put("mail.pop3.connectiontimeout", "60000");
    Session session = Session.getDefaultInstance(props, null);
    // -- Get hold of a POP3 message store, and connect to it --
    store = session.getStore("pop3");
    store.connect(POP3Server,995, usr, pwd);
    System.out.println("Connected");
    // -- Try to get hold of the default folder --
    folder = store.getDefaultFolder();
    if (folder == null) throw new Exception("No default folder");
    // -- ...and its INBOX --
    folder = folder.getFolder("INBOX");
    if (folder == null) throw new Exception("No POP3 INBOX");
    // -- Open the folder for read_write (to be able to delete message) --
    folder.open(Folder.READ_WRITE);
    // -- Get the message wrappers and process them --
    Message[] msgs = folder.getMessages();
    for (int msgNum = 0; msgNum < msgs.length; msgNum++){
    saveMessage(msgs[msgNum]);
    System.out.println("No more messages");
    return ("SUCCESS");
    catch (Exception ex){
    ex.printStackTrace();
    return ex.toString();
    finally{
    // -- Close down nicely --
    try{
    // close(true), to expunge deleted messages
    if (folder!=null) folder.close(true);
    if (store!=null) store.close();
    catch (Exception ex){
    //ex.printStackTrace();
    return ex.toString();
    Then create function receivemail.
    create or replace function receivemail(pop3_server in string,
    pop3_usr in string,
    pop3_pwd in string)
    return varchar2
    is language java name
    'ReceiveMail.Receive(java.lang.String,
    java.lang.String,
    java.lang.String) return String';
    And then trying to execute function receivemail, but I am getting following error.
    SQL> set serveroutput on
    SQL>
    SQL> Declare
    2 v_error_msg varchar2(10000);
    3 Begin
    4 v_error_msg:=receivemail('pop3.live.com', '<Hotmail email address>@hotmail.com', 'Hotmail password');
    5 dbms_output.put_line(v_error_msg);
    6 End;
    7 /
    javax.mail.AuthenticationFailedException: EOF on socket
    PL/SQL procedure successfully completed.
    SQL>
    I am requesting, please help me to solve this problem.
    I will be very thankful for your kind help and support.
    Amol......
    Edited by: Amol Karyakarte on 31-May-2012 7:27 AM

    Hello,
    I don't think this is the right forum, as this question seems to have nothing to do with the Oracle Forms tool.
    You'd better ask it in the database forum.
    Francois

  • Reading Inbox - javax.mail.MessagingException: Connect failed;

    I get an error message while trying to read emails by connecting to a company mailbox. The message is as follows:
    javax.mail.MessagingException: Connect failed;
    nested exception is:
         java.net.ConnectException: Connection refused: no further information
         boolean com.sun.mail.pop3.POP3Store.protocolConnect(java.lang.String, int, java.lang.String, java.lang.String)
         void javax.mail.Service.connect(java.lang.String, int, java.lang.String, java.lang.String)
         void javax.mail.Service.connect(java.lang.String, java.lang.String, java.lang.String)
         void GetMessageExample.main(java.lang.String[])
    The code is very simple and as follows:
    import java.io.*;
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class GetMessageExample {
    public static void main (String args[]) throws Exception {
    String host = "companyname.com";
    String username = "user";
    String password = "xxxx";
    try{
    // Create empty properties
    Properties props = new Properties();
    // Get session
    Session session = Session.getInstance(props, null);
    // Get the store
    Store store = session.getStore("pop3");
    store.connect(host, username, password);
    // Get folder
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);
    BufferedReader reader = new BufferedReader (
    new InputStreamReader(System.in));
    // Get directory
    Message message[] = folder.getMessages();
    for (int i=0, n=message.length; i<n; i++) {
    System.out.println(i + ": " + message.getFrom()[0]
    + "\t" + message[i].getSubject());
    // Close connection
    folder.close(false);
    store.close();
    } catch (Exception e) {
    e.printStackTrace();
    I have a two part question:
    1. At home I am using a dial-up connection it works when I change the settings to an email account as provided by the local ISP.
    I have tried it with both "pop3" and "imap" in
    Store store = session.getStore("pop3");
    for the company email but it does not work.
    Is this a problem with company security? Maybe firewall/proxy error? If so how do I get around it?
    2. Also, when I am in the office (LAN used to connect to Internet) I cannot even get a connection to the ISP account - similar problem or different?
    Any thoughts and help most appreciated.
    Thanks in advance,
    Mark

    It could be that the mail server is not accepting connections from the machine you are on. Have you tried using Outlook Express or the Netscape email client to connect to the server/account from the machine that is getting the failure?

  • Javax.mail.NoSuchProviderException: No provider for ifs1

    Similar to the question found in William Troper's thread run on
    November 1. We had mail code working fine, changed some
    variables to incorporate a migratable build and have now lost
    our mail functionality.
    We have followed William's advice by renaming all of Sun's Mail
    classes in the ~\9ifs\settings\META-INF directory and still no
    joy.
    Does anyone have any ideas of what is causing a "No provider for
    ifs1" error message?
    Cheers,
    Susan

    Hi Scott,
    These (among other) items are in my CLASSPATH (printed out at
    runtime)
    /projects/intranet/lib/mail.jar:/app/oracle/product/9.0.1S/9ifs/s
    ettings/META-INF:
    Here is my stack. Also, the code is EXACLTY the same between
    what was working and what is now not. Thanks for looking in to
    this:
    javax.mail.NoSuchProviderException: No provider for ifs1
         at javax.mail.Session.getProvider(Session.java:249)
         at javax.mail.Session.getTransport(Session.java:442)
         at javax.mail.Session.getTransport(Session.java:423)
         at com.mim.intranet.utils.MessageFactory.sendMesg
    (MessageFactory.java:130)
         at
    com.mim.intranet.unittest.utils.MessagingUT.testValidMesg
    (MessagingUT.java:56)
         at java.lang.reflect.Method.invoke(Native Method)
         at junit.framework.TestCase.runTest(TestCase.java:166)
         at junit.framework.TestCase.runBare(TestCase.java:140)
         at junit.framework.TestResult$1.protect
    (TestResult.java:106)
         at junit.framework.TestResult.runProtected
    (TestResult.java:124)
         at junit.framework.TestResult.run(TestResult.java:109)
         at junit.framework.TestCase.run(TestCase.java:131)
         at junit.framework.TestSuite.runTest(TestSuite.java:173)
         at junit.framework.TestSuite.run(TestSuite.java:168)
         at junit.framework.TestSuite.runTest(TestSuite.java:173)
         at junit.framework.TestSuite.run(TestSuite.java:168)
         at junit.textui.TestRunner.doRun(TestRunner.java:74)
         at junit.textui.TestRunner.run(TestRunner.java:200)
         at com.mim.intranet.unittest.AllTests.main
    (AllTests.java:40)
    4887 [main] WARN com.mim.intranet.unittest.utils.MessagingUT -
    Sending Exception
    F
    Time: 4.898
    There was 1 failure:
    1) testValidMesg(com.mim.intranet.unittest.utils.MessagingUT)
    junit.framework.AssertionFailedError: Failed sending message :
    com.mim.intranet.exception.IntranetException: Failed sending
    message encountered unexpected exception
    Wrapped Exception is : javax.mail.NoSuchProviderException: No
    provider for ifs1
         at
    com.mim.intranet.unittest.utils.MessagingUT.testValidMesg
    (MessagingUT.java:63)
         at com.mim.intranet.unittest.AllTests.main
    (AllTests.java:40)
    FAILURES!!!
    Tests run: 1, Failures: 1, Errors: 0
    com.mim.intranet.exception.IntranetException: Failed sending
    message encountered unexpected exception
    Wrapped Exception is : javax.mail.NoSuchProviderException: No
    provider for ifs1
         at com.mim.intranet.utils.MessageFactory.sendMesg
    (MessageFactory.java:187)
         at
    com.mim.intranet.unittest.utils.MessagingUT.testValidMesg
    (MessagingUT.java:56)
         at java.lang.reflect.Method.invoke(Native Method)
         at junit.framework.TestCase.runTest(TestCase.java:166)
         at junit.framework.TestCase.runBare(TestCase.java:140)
         at junit.framework.TestResult$1.protect
    (TestResult.java:106)
         at junit.framework.TestResult.runProtected
    (TestResult.java:124)
         at junit.framework.TestResult.run(TestResult.java:109)
         at junit.framework.TestCase.run(TestCase.java:131)
         at junit.framework.TestSuite.runTest(TestSuite.java:173)
         at junit.framework.TestSuite.run(TestSuite.java:168)
         at junit.framework.TestSuite.runTest(TestSuite.java:173)
         at junit.framework.TestSuite.run(TestSuite.java:168)
         at junit.textui.TestRunner.doRun(TestRunner.java:74)
         at junit.textui.TestRunner.run(TestRunner.java:200)
         at com.mim.intranet.unittest.AllTests.main
    (AllTests.java:40)
    -----------------------------------------------------------------

  • Javax.mail.MessagingException: Not Connected

    Hi All,
    I am trying to read the message from pop.gmail.com using JavaMail API.I ma using POP3 protocol for it.
    But I got the following Exception
    javax.mail.MessagingException: Not Connected
    at com.sun.mail.pop3.POP3Store.checkConnected(POP3Store.java:279)
         at com.sun.mail.pop3.POP3Store.getFolder(POP3Store.java:261)
         at MailReceipt.connect(MailReceipt.java:97)
         at MailReceipt.mailRecieve(MailReceipt.java:62)
         at MailReceipt.main(MailReceipt.java:53)
    I got This Error at the line
    folder = store.getFolder("INBOX");
    in my program.
    Please Help me ion this regards.Thanks in Adnavce..
    Thanx & Regards
    Sandeep Verma

    Well, I've never used this API but it seems 100% clear what's wrong. And 5 seconds with Google has revealed that there's a method on that class which looks like it will address the issue.
    If you can't even read basic error messages, you should seriously question whether you should be programming.

  • Random javax.mail.FolderNotFoundException

    Hi all,
    we have a java application hosted on Win 2000 wich is using javamail api to interact with MS Exchange 2003. Basically is getting folders and iterating trough them.
    From time to time we get an error about javax.mail.FolderNotFoundException.
    This is happening really randomly and not on the same folder, the ms event viewer doesn't say so much, and the application has basic log4j error with no stack trace, only the getMessage().
    My question is, do you know of any existing bug between the three systems wich could cause such error ?
    Where do you think I should start to solve the problem ? Network ? Java ?
    thanks in advance...

    Turn on session debugging and examine the
    protocol trace. See the JavaMail FAQ.

  • Error: javax.mail.SendFailedException

    Hi all,
    I have a requirement to send a mail on click of a button. I have written a simple java code using java mail API. But while running the application i am getting
    javax.mail.SendFailedException: Sending failed;  nested exception is: javax.mail.SendFailedException: Invalid Addresses;  nested exception is: javax.mail.SendFailedException: 550 5.7.1 Unable to relay for [email protected]
    If i run the java code as a standalone java application everything is fine. Only in webdynpro application i am getting the above mentioned error.
    My question is do we have to configure any settings in the WAS. If so, can somebody give me a detailed answer how to do the configuration.
    Thanks and Regards,
    Rathna

    I stopped the Antivirus service and checked the application but it doesn't help.
    Here is the code. But the code is working fine.
    // Get system properties
    Properties props = new Properties();
    // Setup mail server
    props.put("mail.pop3.host","myserver");
    props.put("mail.pop3.auth","true");
    Authentication auth = new Authentication("[email protected]","abcd");
                   Session session = Session.getInstance(props,auth);
                   Store store = session.getStore("pop3");
                   store.connect("myserver","[email protected]","abcd");
                   System.out.println("Connected");
                   MimeMessage message =  new MimeMessage(session);
                   message.setFrom(new InternetAddress("[email protected]"));
                   message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("[email protected]"));
                   message.setSubject("Hello JavaMail Attachment");
                   // create the message part
                   MimeBodyPart messageBodyPart =  new MimeBodyPart();
                   //fill message
                   messageBodyPart.setText("Hi");
                   Multipart multipart = new MimeMultipart();
                   multipart.addBodyPart(messageBodyPart);
                   // Part two is attachment
                   messageBodyPart = new MimeBodyPart();
                   String fileAttachment="D:\Message.txt";
                   DataSource source =  new FileDataSource(fileAttachment);
                   messageBodyPart.setDataHandler(new DataHandler(source));
                   messageBodyPart.setFileName(fileAttachment);
                   multipart.addBodyPart(messageBodyPart);
                   // Put parts in message
                   message.setContent(multipart);
                                  // Send the message
                   javax.mail.Transport.send(message);
                   System.out.println("Mail sent successfully");
                   store.close();

  • Javax.mail.mailexception while am trying to send the mail

    Hi.
    Am trying to send a mail from ADF Application am using SMTP Server to send the mail
    I have added javamail.jar in my libraries
    This is the code am using to send
        public String send() {
            // Add event code here...
            String to;
            to = new String();
            String host = "localhost";
            String from = "[email protected]";
            Properties properties = System.getProperties();
            properties.setProperty("mail.smtp.host", host);
            Session session = Session.getDefaultInstance(properties);
            try{
                MimeMessage message = new MimeMessage (session);
                message.setFrom(new InternetAddress(from));
                message.addRecipient(Message.RecipientType.TO,new InternetAddress("to"));
                message.setSubject(subj);
                message.setText(body);
                Transport.send(message);
                System.out.println ("Sent Message Successfully");
            catch(MessagingException max){
                max.printStackTrace();
            return null;
        }Am getting the exception as below
    javax.mail.MessagingException: [EOF]
         at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
         at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1321)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:637)
         at javax.mail.Transport.send0(Transport.java:189)
         at javax.mail.Transport.send(Transport.java:118)
         at view.SendMail.send(SendMail.java:78)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.sun.el.parser.AstValue.invoke(Unknown Source)
         at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
    Could any one pls help me?
    regards,
    Prasad K T.

    This question is better asked in a java forum or JavaMail forum {forum:id=975}
    Timo

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

  • Problem with recognizing javax.mail.* class ?

    Hi Folks,
    I am new to JavaMail usage on a standalone java program. I did write a java program to send a mail. The problem is it is not recognizing the javax.mail.* class, though i added on the classpath. I too added mail.jar file in the c:\program files\java\jdk1.5.0_16\lib and added the reference same to the classpath and still it is not recognizing. Do i miss something? help me out guys.
    Regards,
    jaisuryah

    Hi Shannon,
    I hope the configuration i did is well. Yah am running the Java from the command line and i dont know why importing the package of javax.mail.* classes are not recognizing. I did unzipped the zip file and placed all the JAR files to lib folder of my installed JDK and referenced the JDK to classpath in environment variable also.
    Regards,
    Jaisuryah

  • Package javax.mail does not exist (Still having trouble)

    Good Morning
    I know that there are several posts regarding issues with javamail. I have viewed them for the past hour. While several of them address my issue I have been unable to locate a solution.
    Bare with me please, I am making this post very thorough. The other threads I have read are frusterating because the problems people tend to post are not clear.
    I am trying to run "msgsend" which is a provided demo of javamail-1.4 using command prompt (start - run - cmd) with the javac command.
    The output below is directly pasted from command prompt and written in bold.
    C:\download\javamail-1.4\demo>javac msgsend.java
    C:\download\javamail-1.4\demo>javac msgsend.java
    msgsend.java:44: package javax.mail does not exist
    import javax.mail.*;
    ^
    msgsend.java:45: package javax.mail.internet does not exist
    import javax.mail.internet.*;
    ^
    msgsend.java:140: cannot find symbol
    symbol : class Session
    location: class msgsend
    Session session = Session.getInstance(props, null);
    ^
    msgsend.java:140: cannot find symbol
    symbol : variable Session
    location: class msgsend
    Session session = Session.getInstance(props, null);
    ^
    msgsend.java:145: cannot find symbol
    symbol : class Message
    location: class msgsend
    Message msg = new MimeMessage(session);
    ^
    msgsend.java:145: cannot find symbol
    symbol : class MimeMessage
    location: class msgsend
    Message msg = new MimeMessage(session);
    ^
    msgsend.java:147: cannot find symbol
    symbol : class InternetAddress
    location: class msgsend
    msg.setFrom(new InternetAddress(from));
    ^
    msgsend.java:151: package Message does not exist
    msg.setRecipients(Message.RecipientType.TO,
    ^
    msgsend.java:152: cannot find symbol
    symbol : variable InternetAddress
    location: class msgsend
    InternetAddress.parse(to,
    ^
    msgsend.java:154: package Message does not exist
    msg.setRecipients(Message.RecipientType.CC,
    ^
    msgsend.java:155: cannot find symbol
    symbol : variable InternetAddress
    location: class msgsend
    InternetAddress.parse(cc,
    ^
    msgsend.java:157: package Message does not exist
    msg.setRecipients(Message.RecipientType.BCC,
    ^
    msgsend.java:158: cannot find symbol
    symbol : variable InternetAddress
    location: class msgsend
    InternetAddress.parse(bcc,
    ^
    msgsend.java:167: cannot find symbol
    symbol : class MimeBodyPart
    location: class msgsend
    MimeBodyPart mbp1 = new MimeBodyPart();
    ^
    msgsend.java:167: cannot find symbol
    symbol : class MimeBodyPart
    location: class msgsend
    MimeBodyPart mbp1 = new MimeBodyPart();
    ^
    msgsend.java:169: cannot find symbol
    symbol : class MimeBodyPart
    location: class msgsend
    MimeBodyPart mbp2 = new MimeBodyPart();
    ^
    msgsend.java:169: cannot find symbol
    symbol : class MimeBodyPart
    location: class msgsend
    MimeBodyPart mbp2 = new MimeBodyPart();
    ^
    msgsend.java:171: cannot find symbol
    symbol : class MimeMultipart
    location: class msgsend
    MimeMultipart mp = new MimeMultipart();
    ^
    msgsend.java:171: cannot find symbol
    symbol : class MimeMultipart
    location: class msgsend
    MimeMultipart mp = new MimeMultipart();
    ^
    msgsend.java:185: cannot find symbol
    symbol : variable Transport
    location: class msgsend
    Transport.send(msg);
    ^
    msgsend.java:193: cannot find symbol
    symbol : class Store
    location: class msgsend
    Store store = null;
    ^
    msgsend.java:195: cannot find symbol
    symbol : class URLName
    location: class msgsend
    URLName urln = new URLName(url);
    ^
    msgsend.java:195: cannot find symbol
    symbol : class URLName
    location: class msgsend
    URLName urln = new URLName(url);
    ^
    msgsend.java:212: cannot find symbol
    symbol : class Folder
    location: class msgsend
    Folder folder = store.getFolder(record);
    ^
    msgsend.java:218: cannot find symbol
    symbol : variable Folder
    location: class msgsend
    folder.create(Folder.HOLDS_MESSAGES);
    ^
    msgsend.java:220: cannot find symbol
    symbol : class Message
    location: class msgsend
    Message[] msgs = new Message[1];
    ^
    msgsend.java:220: cannot find symbol
    symbol : class Message
    location: class msgsend
    Message[] msgs = new Message[1];
    27 errors
    Here are the methods I have tried...
    1. Make sure you have most current version of Java
    2. Reinstall Java
    3. Attempt to compile in an IDE (Attempted in Eclipse 3.2)
    4. Set class path
    Some sources suggest "CLASSPATH" some suggest "CLASS PATH" as the variable name. I have tried both.
    Below is what the classpath looks like in bold.
    Variable Name: CLASS PATH
    Variable value: c:\download\javamail-1.4\mail.jar;C:\download\jaf-1.1\activation.jar;.
    I have double checked all folder names and copy pasted all entries to eliminate typos. Javamail-1.4 and jaf-1.1 are both located in c:\download which is the same location Class Path points to.
    Thank you very much for your input and effort. I can imagine how frusterating it is responding to 20million javamail posts :) (that may be a bit of an overstatement!)
    Thank you again!
    Irbi
    Message was edited by:
    irbi
    Message was edited by:
    irbi

    Yes - I have read that part of the README and did exactly as it has said in a previous attempt. I should have mentioned that here I'm sorry :)
    I moved the .jar files into the download folder and set the classpath exactly as the readme shows.
    When I do that the msgsend.java compiles correctly but it still does not run.
    Below is what happens.
    C:\download\javamail-1.4\demo>set CLASSPATH=%CLASSPATH%;c:\download\javamail-1.4
    \mail.jar;%CLASSPATH%;c:\download\jaf-1.1\activation.jar.
    C:\download\javamail-1.4\demo>javac msgsend.java
    C:\download\javamail-1.4\demo>java msgsend.java
    Exception in thread "main" java.lang.NoClassDefFoundError: msgsend/java
    C:\download\javamail-1.4\demo>
    I have tried fixing this error as well via forums and FAQs but it seems to be the most generic error.
    One suggestion was to clear your classpath. I tried this with a test hello world program which was giving the same error - "NoClassDefFoundError". By clearing the classpath I was able to get the hello world program to run without this error. But I can't just clear the classpath in this instance because it needs to point to mail.jar and activation.jar for the program to compile.
    Thanks again for all of your efforts. You are more appreciated than you know.

  • Exception in thread "main" javax.mail.NoSuchProviderException: invalid prov

    HI,
    I am trying to read mails from my inbox i amgetting the ErrorC:\javamail>java
    Readmail
    Exception in thread "main" javax.mail.NoSuchProviderException: No provider for IMAP
            at javax.mail.Session.getProvider(Session.java:455)
            at javax.mail.Session.getStore(Session.java:530)
            at javax.mail.Session.getStore(Session.java:510)
            at Readmail.main(Readmail.java:24)My Code is    {
    String host = "hostname";
    String username = "user";
    String password = "password";
    // Create empty properties
    Properties props = new Properties();
    // Get session
    Session session = Session.getDefaultInstance(props,null);
    // Get the store
    Store store = session.getStore("IMAP");
    store.connect(host, username, password);
    // Get folder
    Folder folder = store.getFolder("Inbox");
    folder.open(Folder.READ_ONLY);
    // Get directory
    Message message[] = folder.getMessages();
    for (int i=0, n=message.length; i<n; i++)
       System.out.println(i + ": " + message.getFrom()[0]
    + "\t" + message[i].getSubject());
    // Close connection
    folder.close(false);
    store.close();
    I have also tried POP3 and MIME and SMTP
    Can anyone help me Thanks

    hi bshannon,
    I am getting the same error for others but for pop3 the error is as below
    Exception in thread "main" javax.mail.MessagingException: Connect failed;
      nested exception is:
            java.net.ConnectException: Connection refused: connect
            at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
            at javax.mail.Service.connect(Service.java:275)
            at javax.mail.Service.connect(Service.java:156)
            at Readmail.main(Readmail.java:25)
    Caused by: java.net.ConnectException: Connection refused: connect
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
            at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
            at java.net.Socket.connect(Socket.java:452)
            at java.net.Socket.connect(Socket.java:402)
            at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
            at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
            at com.sun.mail.pop3.Protocol.<init>(Protocol.java:81)
            at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)
            at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)
            ... 3 more

  • How to get support of javax.Mail in Tomcat

    Hello
    I am tring to run a program which need javax.MAil and javax.activation packages in jsp. i am using tomcat
    but i am not able to run that program as it giving error of package not found . so plz tell me how i can use other API's in tomcat
    regards
    Raj

    Hello sir thx for ur reply ...but i already did that on
    means set classpath for both jar files
    r there any classpath variable in tomcat also?
    as i set my local classpath environment variable
    when i import that package that is javax.mail
    it gives me error on import statement...i thing
    when we import any package it searchs that package
    in WEB-INF/class dir...so plzz....reply and give me
    ome suggestions.

  • Javax.mail CSV file attachment corrupt?

    I'm having some trouble with attaching a file to an outgoing email, it's a CSV file and when it is uploaded/attached to the email, it becomes "corrupt". Excel will still open it but if I open it in notepad the formatting is noticeably messed up. I need it to retain all the correct return carriages and line feeds, which I believe are what are getting mingled. (Another program must read it and this formatting is messing everything up).
    Here's the code:
    MimeBodyPart messageBodyPart =
                     new MimeBodyPart();
             //fill message
             messageBodyPart.setText(outBoundMessage);
             Multipart multipart = new MimeMultipart();
             multipart.addBodyPart(messageBodyPart);
             if (fileAttachment != null) {
                // Part two is attachment
                MimeBodyPart attachment = new MimeBodyPart();
                attachment.attachFile(fileAttachment);
                attachment.setFileName(fileAttachment.getName());
                attachment.setHeader("type", "text/csv");
                multipart.addBodyPart(attachment);
             // Put parts in message
             message.setContent(multipart);The other parts of the message are being created and attached where necessary. My guess is that it's not transferring in binary? I've never really done this sort of thing so if anyone could lend a hand and show me how to properly attach files so they don't get altered in anyway I would greatly appreciate it.

    Hi,
    I am sending csv file as an attachment by using below code
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class AttchmtMail
        String finaldt;
            public  void mailAtchmt(String fname,String dt) {
                String   to="[email protected]";
               String from = "[email protected]";
              String to2="[email protected]";
                 String host = "xxx.xx.xxx.xxx";
                // Create properties, get Session
                Properties props = new Properties();
                // If using static Transport.send(),
                // need to specify which host to send it to
                props.put("mail.smtp.host", host);
                // To see what is going on behind the scene
                props.put("mail.debug", "true");
                Session session = Session.getInstance(props);
                try {
                    // Instantiatee a message
                    Transport bus = session.getTransport("smtp");
                    bus.connect();
                    Message msg = new MimeMessage(session);
                    //Set message attributes
                    msg.setFrom(new InternetAddress(from));
                    InternetAddress[] address = {new InternetAddress(to),new InternetAddress(to2)};
                    msg.setRecipients(Message.RecipientType.TO, address);
                    msg.setSubject("New OU's on "+dt+".");
                    msg.setSentDate(new Date());
                   // String filename= "C:/Feeds/"+finaldt+"/"+files;
    String file1= fname;
    File f1=new File(file1);
    if(f1.exists())
    setFileAsAttachment(msg, file1);
    else
    //setFileAsAttachment(msg,"","",info);
    msg.saveChanges();
    bus.sendMessage(msg, address);
    bus.close();
    catch (MessagingException mex) {
    // Prints all nested (chained) exceptions as well
    mex.printStackTrace();
    // How to access nested exceptions
    while (mex.getNextException() != null) {
    // Get next exception in chain
    Exception ex = mex.getNextException();
    ex.printStackTrace();
    if (!(ex instanceof MessagingException)) break;
    else mex = (MessagingException)ex;
    public void setFileAsAttachment(Message msg, String filename)
    throws MessagingException {
    // Create and fill first part
    MimeBodyPart p1 = new MimeBodyPart();
    p1.setText("Dear ,\n\nPlease check the attachment " );
    // Create second part
    MimeBodyPart p2 = new MimeBodyPart();
    // Put a file in the second part
    if(!filename.equals(""))
    FileDataSource fds = new FileDataSource(filename);
    p2.setDataHandler(new DataHandler(fds));
    p2.setFileName(fds.getName());
    // Create the Multipart. Add BodyParts to it.
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(p1);
    if(!filename.equals(""))
    mp.addBodyPart(p2);
    } // Set Multipart as the message's content
    msg.setContent(mp);
    }//End of class
    Madhu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for