SMTP arguments to properties.put()

I dont understand what are the actual values I need tp substitute for the method put("mail.smtp.host","mail.yourisp.com").
Is the first argument the ougoing mail server ?For example I use comcast and my outgoing smtp server that I am using in Ximian is smtp.comcast.net. So is the first argument smtp.comcast.net
What do I need to put for the second argument.?
More specifically what is the difference between the first and second arguments?
RS

The first argument is the name of the property, so it must be as given in the example. The second argument is the value of the property, which in this case must be the name of your SMTP server.

Similar Messages

  • SMTP: Transport.send() works, transport.sendMessage() not ("not connected")

    Sendig a SMTP Message to a running SMTP Server on localhost, port 25 works fine, if i use
    Transport.send( myMessage);However, it does not when i use
    Transport tr = session.getTransport(..);
    tr.connect("localhost", 25, "user", "pass");
    tr.sendMessage ( myMessage );In this case, the connect seems to work (actually, debugging in eclipse has shown that the Transport-internal field "connected" is set to true!), but sending myMessage throws the following Exception:
    java.lang.IllegalStateException: Not connected
         at com.sun.mail.smtp.SMTPTransport.checkConnected SMTPTransport.java:1398)
         at com.sun.mail.smtp.SMTPTransport.sendMessage SMTPTransport.java:489)calling transport.isConnected() also returnsfalseWell, using the static way is a first workaround, that i don't want to use because of the bad performance (need to send lot of mails under certain circumstances).
    Does anyone have an idea whats wrong?

    If your SMTP server does not require authentication, do not use "Transport.connect(server, port, username, password)", use "Transport.connect()" instead.
    If you SMTP server does require authentication, you should have the "mail.smtp.auth" property of the session set as "true".
    The following code is working properly on my machine.
    import java.lang.*;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.event.*;
    import javax.mail.internet.*;
    public class SendMail {
    static String mailHost = "mail.mydomain.com";
    static String source = "[email protected]";
    static String subject = "Test JavaMail";
    static String content = "Content";
    public static void main(String args[]) {
    Properties properties = new Properties();
    properties.put("mail.smtp.host", mailHost);
    properties.put("mail.from", source);
    Session session = Session.getInstance(properties, null);
    try {
    Message message = new MimeMessage(session);
    InternetAddress[] address = new InternetAddress[args.length];
    for (int i = 0; i < args.length; i++)
    address[i] = new InternetAddress(args);
    message.setRecipients(Message.RecipientType.TO, address);
    message.setFrom(new InternetAddress(source));
    message.setSubject(subject);
    message.setContent(content, "text/plain");
    Transport transport = session.getTransport(address[0]);
    transport.addConnectionListener(new ConnectionHandler());
    transport.addTransportListener(new TransportHandler());
    transport.connect();
    transport.sendMessage(message, address);
    } catch (Exception e) {
    System.out.println(e.toString());
    class ConnectionHandler extends ConnectionAdapter {
    public void opened(ConnectionEvent e) {
    System.out.println("Connection opened.");
    public void disconnected(ConnectionEvent e) {
    System.out.println("Connection disconnected.");
    public void closed(ConnectionEvent e) {
    System.out.println("Connection closed.");
    class TransportHandler extends TransportAdapter {
    public void messageDelivered(TransportEvent e) {
    System.out.println("Message delivered.");
    public void messageNotDelivered(TransportEvent e) {
    System.out.println("Message NOT delivered.");
    public void messagePartialDelivered(TransportEvent e) {
    System.out.println("Message partially delivered.");

  • SMTP Server Changing Unpredictably

    I am experiencing weird behavior in my JavaMail program. At first, mail sending works fine through a remote mail server. After the program has been running for a while, though, it starts trying to send messages through localhost.
    I am creating my session once as follows and use it and only it for all mail handling in my program:
        Properties properties = System.getProperties();
        properties.put("mail.smtp.host", smtpHost);
        properties.put("mail.smtp.auth", "true");
        // Disable the TOP command.  Otherwise, JavaMail will raise an
        // exception in calls to folder.fetch() and message.getContent()
        // when dealing with a qmail server and messages that begin with
        // a dot.  See
        //   http://forum.java.sun.com/thread.jspa?messageID=4395487?
        // for details.
        properties.put("mail.pop3.disabletop", "true");
        Authenticator authenticator = new FixedAuthenticator(userName, password);
        Session session = Session.getInstance(properties, authenticator);I create a message to send as follows:
        MimeMessage mimeMessage = new MimeMessage(session);
        toAddresses = InternetAddress.parse(to, false);
        mimeMessage.setRecipients(Message.RecipientType.TO, toAddresses);
        ccAddresses = InternetAddress.parse(cc, false);
        mimeMessage.setRecipients(Message.RecipientType.CC, ccAddresses);
        mimeMessage.setSubject(subject);
        InternetAddress fromAddress = new InternetAddress(from);
        mimeMessage.setFrom(fromAddress);
        Address replyToAddresses[] = { new InternetAddress(replyTo) };
        mimeMessage.setReplyTo(replyToAddresses);
        DataHandler dataHandler = createDataHandler(inputStream, contentType);
        mimeMessage.setDataHandler(dataHandler);I send the message as follows:
        Transport.send(mimeMessage);I dug around in this forum's archives and found various references to multithreaded apps having this problem due to use of statics and system properties. I'm thinking I can fix the problem by getting an instance of the Transport class from the Session and sending the message through it instead of calling the static Transport.send() method. Sound right? Or do I also have to change the way I'm setting up the Properties object?

    Here is my thinking, which may or may not be valid:
    1. My POP3 server is establishing connections with
    SMTP servers on the SMTP port.
    2. When my app (running on the same machine as the
    POP3 server) tries to send mail using a remote SMTP
    server, the app needs to open the SMTP port that is
    already tied up by the POP3 server.You would have to be doing something very unusual for that
    to happen. The client port is assigned arbitrarily and is unrelated
    to the server port you're connecting to. Two clients using different
    client ports can connect to the same server port on the same server.
    3. In response to the busy SMTP port, somehow
    JavaMail is somehow retrying the send using the
    default SMTP server (localhost).No, it doesn't do that.

  • Email sending Problem:smtps---SSL---TLS??

    Hi,
    I Have a Problem bei Sending a email with Attachement from extranet, I have writting my Programm which will send my email Through TLS, with Thunderbird
    I can sending there alle emails through TLS, I have taking the seem Properties :
    emai Server Name, Protocol:smtp port:25 und througt TLS, so Now I will show you my Code und the compile Failure, I appreciate so much your Help, I don't find any Help here in Forum.
    My Code:
    public void sendAttachment(String ausgangsMailServer, String user, String password,String sender, String receiver, String filename) throws MessagingException{
              Properties properties = System.getProperties();          
              properties.put("mail.transport.protocol","smtps");
              properties.put("mail.smtps.ssl", "true");
              properties.put("mail.smtps.starttls.enable","true");
              properties.put("mail.smtps.auth", "true");
              properties.put("mail.smtps.debug", "true");
              properties.put("mail.smtps.socketFactory.port", "25");
              properties.put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
              properties.put("mail.smtps.socketFactory.fallback", "false");
    SecurityManager security = System.getSecurityManager();
              Session session = Session.getInstance(properties, new MailAuthenticator());                         
              Transport transport = session.getTransport("smtps");                    
              transport.connect(ausgangsMailServer, user, password);          
              Message message = getMessage(session, sender, receiver,filename);
              message.saveChanges();
              transport.sendMessage(message, message.getAllRecipients());          
              transport.close();
         public Message getMessage(Session session, String sender, String receiver, String filename) throws MessagingException{          
         Message message = new MimeMessage(session);                                                                                                                   
    message.setSubject("attachment");
         message.setFrom(new InternetAddress(sender));
         message.addRecipient(Message.RecipientType.TO, new InternetAddress(receiver));
         Multipart multipart = new MimeMultipart();
         BodyPart bp = new MimeBodyPart();
         bp.setText("Attachment Mail");
         multipart.addBodyPart(bp);
         bp = new MimeBodyPart();
         DataSource source = new FileDataSource(filename);
         bp.setDataHandler(new DataHandler(source));
         bp.setFileName(filename);     
         multipart.addBodyPart(bp);
         message.setContent(multipart);                              
         return message;
         public class MailAuthenticator extends Authenticator{
              public MailAuthenticator(){
              public PasswordAuthentication getPasswordAuthentication(){
                   return new PasswordAuthentication("radouane","mypaaword");
    And I call the methode sendAttachment in a EJB Methode I Use Jboss als Server in my web application.
    This is now my failure:
    05:07:21,382 INFO [STDOUT] javax.mail.NoSuchProviderException: smtps
    05:07:21,382 INFO [STDOUT] at javax.mail.Session.getService(Session.java:76
    4)
    05:07:21,382 INFO [STDOUT] at javax.mail.Session.getTransport(Session.java:
    689)
    05:07:21,382 INFO [STDOUT] at javax.mail.Session.getTransport(Session.java:
    632)
    05:07:21,382 INFO [STDOUT] at javax.mail.Session.getTransport(Session.java:
    612)
    I have Using a smtps protocol , by using smtp I Had this Failure:
    14:15:11,164 INFO [STDOUT] javax.mail.MessagingException: Exception reading res
    ponse;
    nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connecti
    on?
    14:15:11,164 INFO [STDOUT] at com.sun.mail.smtp.SMTPTransport.readServerRes
    ponse(SMTPTransport.java:1090)
    14:15:11,164 INFO [STDOUT] at com.sun.mail.smtp.SMTPTransport.openServer(SM
    TPTransport.java:986)
    14:15:11,164 INFO [STDOUT] at com.sun.mail.smtp.SMTPTransport.protocolConne
    ct(SMTPTransport.java:197)
    14:15:11,164 INFO [STDOUT] at javax.mail.Service.connect(Service.java:233)
    14:15:11,164 INFO [STDOUT] at javax.mail.Service.connect(Service.java:134)
    For your help I say Thanks.
    Radouane

    Hi,
    I want just writtefor you my javamail debug Infomationen by J2SE Application and bei J2EE application. By j2se was that sending successful, by j2ee application is a problem by TSL.
    Hier Debug for j2se application:
    DEBUG: setDebug: JavaMail version 1.4ea
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsys
    tems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: trying to connect to host "mail.cs.tu-berlin.de", port 25, isSSL false
    220 mailhost.cs.tu-berlin.de ESMTP Postfix
    DEBUG SMTP: connected to host "mail.cs.tu-berlin.de", port: 25
    EHLO meknes
    250-mailhost.cs.tu-berlin.de
    250-PIPELINING
    250-SIZE
    250-VRFY
    250-ETRN
    250-STARTTLS
    250-ENHANCEDSTATUSCODES
    250 8BITMIME
    DEBUG SMTP: Found extension "PIPELINING", arg ""
    DEBUG SMTP: Found extension "SIZE", arg ""
    DEBUG SMTP: Found extension "VRFY", arg ""
    DEBUG SMTP: Found extension "ETRN", arg ""
    DEBUG SMTP: Found extension "STARTTLS", arg ""
    DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
    DEBUG SMTP: Found extension "8BITMIME", arg ""
    STARTTLS
    220 2.0.0 Ready to start TLS
    EHLO meknes
    250-mailhost.cs.tu-berlin.de
    250-PIPELINING
    250-SIZE
    250-VRFY
    250-ETRN
    250-AUTH PLAIN LOGIN
    250-ENHANCEDSTATUSCODES
    250 8BITMIME
    DEBUG SMTP: Found extension "PIPELINING", arg ""
    DEBUG SMTP: Found extension "SIZE", arg ""
    DEBUG SMTP: Found extension "VRFY", arg ""
    DEBUG SMTP: Found extension "ETRN", arg ""
    DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
    DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
    DEBUG SMTP: Found extension "8BITMIME", arg ""
    DEBUG SMTP: Attempt to authenticate
    AUTH LOGIN
    334 oioohbzfavsa7
    mnhgvas8799800U=
    30987hasabhsasa6
    Y2hiijsasisas=
    235 2.0.0 Authentication successful
    DEBUG SMTP: use8bit false
    MAIL FROM:<[email protected]>
    250 2.1.0 Ok
    RCPT TO:<[email protected]>
    250 2.1.5 Ok
    DEBUG SMTP: Verified Addresses
    DEBUG SMTP: [email protected]
    DATA
    354 End data with <CR><LF>.<CR><LF>
    From: [email protected]
    To: [email protected]
    Message-ID: <9971081.01168741860633.JavaMail.radouane@meknes>
    Subject: attachment
    MIME-Version: 1.0
    Content-Type: multipart/mixed;
    boundary="----=_Part_0_25199001.1168741860423"
    ------=_Part_0_25199001.1168741860423
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Attachment Mail
    ------=_Part_0_25199001.1168741860423
    Content-Type: application/octet-stream; name=filename
    Content-Transfer-Encoding: 7bit
    Content-Disposition: attachment; filename=filename
    Now by J2ee application---I use jboss:
    2007-01-14 03:27:28,769 INFO [STDOUT] DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    2007-01-14 03:27:28,769 INFO [STDOUT] DEBUG SMTP: useEhlo true, useAuth true
    2007-01-14 03:27:28,769 INFO [STDOUT] DEBUG SMTP: trying to connect to host "mail.cs.tu-berlin.de", port 25
    2007-01-14 03:27:28,909 INFO [STDOUT] 220 mailhost.cs.tu-berlin.de ESMTP Postfix
    2007-01-14 03:27:28,909 INFO [STDOUT] DEBUG SMTP: connected to host "mail.cs.tu-berlin.de", port: 25
    2007-01-14 03:27:28,909 INFO [STDOUT] EHLO meknes
    2007-01-14 03:27:28,979 INFO [STDOUT] 250-mailhost.cs.tu-berlin.de
    250-PIPELINING
    250-SIZE
    250-VRFY
    250-ETRN
    250-STARTTLS
    250-ENHANCEDSTATUSCODES
    250 8BITMIME
    2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "PIPELINING", arg ""
    2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "SIZE", arg ""
    2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "VRFY", arg ""
    2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "ETRN", arg ""
    2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "STARTTLS", arg ""
    2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
    2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: Found extension "8BITMIME", arg ""
    2007-01-14 03:27:28,979 INFO [STDOUT] DEBUG SMTP: use8bit false
    2007-01-14 03:27:28,979 INFO [STDOUT] MAIL FROM:<[email protected]>
    2007-01-14 03:27:29,049 INFO [STDOUT] 250 2.1.0 Ok
    2007-01-14 03:27:29,049 INFO [STDOUT] RCPT TO:<[email protected]>
    2007-01-14 03:27:29,159 INFO [STDOUT] 554 5.7.1 <[email protected]>: Recipient address rejected: Access denied
    2007-01-14 03:27:29,159 INFO [STDOUT] DEBUG SMTP: Invalid Addresses
    2007-01-14 03:27:29,159 INFO [STDOUT] DEBUG SMTP: [email protected]
    2007-01-14 03:27:29,159 INFO [STDOUT] DEBUG SMTP: Sending failed because of invalid destination addresses
    2007-01-14 03:27:29,159 INFO [STDOUT] RSET
    2007-01-14 03:27:29,229 INFO [STDOUT] 250 2.0.0 Ok
    2007-01-14 03:27:29,229 INFO [STDOUT] QUIT
    2007-01-14 03:27:29,229 INFO [STDOUT] Error Sending:
    2007-01-14 03:27:29,229 INFO [STDOUT] Sending failed;
    nested exception is:
         class javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
         class javax.mail.SendFailedException: 554 5.7.1 <[email protected]>: Recipient address rejected: Access denied
    2007-01-14 03:27:29,229 INFO [STDOUT] java.lang.NullPointerException
    can someone tell me, where is my problem by j2ee application, it's a ejb class -using jboss-.
    Thanks ,
    Radouane
    Message was edited by:
    radouane.marjani

  • Attachment in mail

    Hi there
    I've got a problem when it comes to adding attachments to a mail. I've got a working mail function that lokk like this:
    import java.util.Properties;
    import javax.activation.DataHandler;
    import javax.activation.FileDataSource;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class EmailSender
    public EmailSender()
    public static void postMail(String s, String s1, String as[], String s2, String s3, String s4, String s5)
    throws Exception
    Properties properties = new Properties();
    properties.put("mail.smtp.host", s);
    properties.put("mail.smtp.user", s1);
    Session session = Session.getInstance(properties, null);
    session.setDebug(true);
    MimeMessage mimemessage = new MimeMessage(session);
    InternetAddress internetaddress = new InternetAddress(s5);
    mimemessage.setFrom(internetaddress);
    InternetAddress ainternetaddress[] = new InternetAddress[as.length];
    for(int i = 0; i < as.length; i++)
    ainternetaddress[i] = new InternetAddress(as);
    mimemessage.setRecipients(javax.mail.Message.RecipientType.TO, ainternetaddress);
    mimemessage.setSubject(s2);
    MimeBodyPart mimebodypart = new MimeBodyPart();
    mimebodypart.setText(s3);
    MimeMultipart mimemultipart = new MimeMultipart();
    mimemultipart.addBodyPart(mimebodypart);
    if(s4 != null && s4.length() > 0)
    MimeBodyPart mimebodypart1 = new MimeBodyPart();
    FileDataSource filedatasource = new FileDataSource(s4);
    mimebodypart1.setDataHandler(new DataHandler(filedatasource));
    mimebodypart1.setFileName(filedatasource.getName());
    mimemultipart.addBodyPart(mimebodypart1);
    mimemessage.setContent(mimemultipart);
    Transport.send(mimemessage);
    The arguments to the postMail function is:
    s = host
    s1 = username
    s2 = recipients
    s3 = subject
    s4 = message
    s4 = filename
    s5 = sender
    It works properly when it comes to sending simple mails. But in the fourth argument you can add a file that should be attached and I can't get it to work. My goal is to be able to both send a file that lies on the server in my webapplication and also be able to send dynamicly generated files with a servlet or jsp page.
    My problem is that the server nerver finds the file that I try to attach. I've tried to put in all the diffrent directories in my webapplication but it just doesn't work.
    Any ideas or tips???
    Thanks / Daniel

    Cancun, Try punching up Mail, then go down under Edit to Attachments,
    and make sure that both lines are checked. This cured my problem.

  • Sending an email from a servlet

    Hi Guys,
    Im trying to send an email from a servlet. I am using the following code:
    IMPORTING LIBRARIES
    import java.util.*;
    import java.io.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    //importing JDBC
    import java.sql.*;
    //email
    import java.net.*;
    import java.text.*; // Used for date formatting.
    BEGIN CLASS
    public class Email3 extends HttpServlet
         private Socket smtpSocket = null;
         private DataOutputStream os = null;
         private DataInputStream is = null;
    public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    PrintWriter out = res.getWriter();
    OUTPUT TAGS FOR WEBPAGE
         out.println("<html>");
    out.println("<head>");
    out.println("<title>FYP</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<center>");
    send email
              //Date dDate = new Date();
              //DateFormat dFormat = _
         //DateFormat.getDateInstance(DateFormat.FULL,Locale.US);
         String m_sHostName="localhost";
         int m_iPort=25;
              try
              { // Open port to server
                   smtpSocket = new Socket(m_sHostName, m_iPort);
                   os = new DataOutputStream(smtpSocket.getOutputStream());
                   is = new DataInputStream(smtpSocket.getInputStream());
                   if(smtpSocket != null && os != null && is != null)
                   { // Connection was made.  Socket is ready for use.
                        out.println("Connection was made. Socket is ready for use.");
                        //[ Code to send email will be placed in here. ]
                        try
                             {   os.writeBytes("HELLO\r\n");
                             // You will add the email address that the server
                             // you are using know you as.
                             os.writeBytes("MAIL From: <[email protected]>\r\n");
                             // Who the email is going to.
                             os.writeBytes("RCPT To: <[email protected]>\r\n");
                             //IF you want to send a CC then you will have to add this
                             os.writeBytes("RCPT Cc: <[email protected]>\r\n");
                             // Now we are ready to add the message and the
                             // header of the email to be sent out.
                             os.writeBytes("DATA\r\n");
                             os.writeBytes("X-Mailer: Via Java\r\n");
                             //os.writeBytes("DATE: " + dFormat.format(dDate) + "\r\n");
                             os.writeBytes("From: Me <[email protected]>\r\n");
                             os.writeBytes("To: YOU <[email protected]>\r\n");
                             //Again if you want to send a CC then add this.
                             os.writeBytes("Cc: CCDUDE <[email protected]>\r\n");
                             //Here you can now add a BCC to the message as well
                             //os.writeBytes("RCPT Bcc: BCCDude<[email protected]>\r\n");
                             String sMessage = "Your subjectline.";
                             os.writeBytes("Subject: Your subjectline here\r\n");
                             os.writeBytes(sMessage + "\r\n");
                             os.writeBytes("\r\n.\r\n");
                             os.writeBytes("QUIT\r\n");
                             // Now send the email off and check the server reply.
                             // Was an OK is reached you are complete.
                             String responseline;
                             while((responseline = is.readLine())!=null)
                             {  // System.out.println(responseline);
                             out.println("responseline= "+responseline+"<br>");
                             if(responseline.indexOf("Ok") != -1)
                                  //out.println("responseline"+responseline);
                             break;
                             catch(Exception e)
                             {  System.out.println("Cannot send email as an error occurred.");
                                  out.println("Cannot send email as an error occurred.");
              catch(Exception e)
              { System.out.println("Host " + m_sHostName + "unknown"); }
              out.println("</center>");
              out.println("</body>");
              out.println("</html>");
              out.close();
    }//end class
    it compiles fine, the connection was made ok but im not receiving the email. When the email is sent off the server reply does not seem to be Ok, as the print statement i tried there is not being executed. When i print the content of my responseline= variable before the if statement i get the following:
    Connection was made. Socket is ready for use. responseline= 220 centaur.elec.qmul.ac.uk ESMTP Exim 3.16 #2 Thu, 09 Jan 2003 15:54:34 +0000
    responseline= 500 Command unrecognized
    responseline= 250 is syntactically correct
    responseline= 550 relaying to prohibited by administrator
    responseline= 500 Command unrecognized
    responseline= 503 No recipient(s).
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 221 Closing connection. Good bye.
    Can anyone help?
    Is there an easier way to send an email from a servlet?
    Thanks
    tzaf

    It's not a matter of "easier way" to send mail from servlet...you are missing a crucial element in your code: authorization to send mail. You need something like this (some of which you have already so note what is different):
            Properties properties = new Properties();
            properties.put("mail.smtp.host", String3 );
            properties.put("mail.smtp.dsn.notify", "SUCCESS" );
            properties.put("mail.smtp.host", "mailservernamegoeshere");
            properties.put("mail.smtp.auth", "true");
            MyAuthenticator auth = new MyAuthenticator();
            auth.setUser("user whos account you want to use goes here");
            auth.setPassword("user password goes here");
            Session session = Session.getDefaultInstance( properties,auth );Here is the auth class:
    class MyAuthenticator extends Authenticator {
       protected String m_strUser     = null;
       protected String m_strPassword = null;
       protected PasswordAuthentication getPasswordAuthentication()  {
          return new PasswordAuthentication(m_strUser,m_strPassword);
       public void setUser(String strUser)  {
          m_strUser = strUser;
       public void setPassword(String strPassword)  {
          m_strPassword = strPassword;

  • PDF File corrupted when being sent by email by tomcat... what's wrong?

    Hi,
    I have been a little frustrated trying tomcat to send a pdf file by email after it have been uploaded to the server.
    First case:
    If i run the same code in windows, it works.
    Second case:
    If i run the same code manually in java in the tomcat linux server it works.
    Third case:
    The problem is when the code is running by tomcat in a jsp page.
    In every situation the email goes to the sender, but in the last one, the reported size of the pdf file is not the same as the first and second case resulting in a pdf corruption. It cannot be opened.
    I am running Tomcat 5.5.17 with jdk 1.5.0.10 in a Redhat Enterprise Linux 4 Server.
    This is the code called by a jsp page.
    package eor;
    import java.util.Date;
    import java.util.Properties;
    import javax.activation.DataHandler;
    import javax.activation.FileDataSource;
    import javax.mail.Authenticator;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Multipart;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    public class SendMailUsingAuthentication {
    private static final String SMTP_AUTH_USER = "user";
    private static final String SMTP_AUTH_PWD = "pass";
    public void sendEmail() {
    String from = "[email protected]";
    String to = "[email protected]";
    String subject = "Sendit from linux ";
    String bodyText = "This is a important message with attachment";
    String filename = "//home//test//HON-SOLMANT28AGO08.pdf";
    Properties properties = new Properties();
    properties.put("mail.smtp.host", "Testmailhost");
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.port", "25");
    Authenticator auth = new SMTPAuthenticator();
    Session session = Session.getInstance(properties, auth);
    session.setDebug(true);
    try {
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);
    message.setSentDate(new Date());
    // Set the email message text.
    MimeBodyPart messagePart = new MimeBodyPart();
    messagePart.setText(bodyText);
    // Set the email attachment file
    MimeBodyPart attachmentPart = new MimeBodyPart();
    FileDataSource fileDataSource = new FileDataSource(filename) {
    @Override
    public String getContentType() {
    return "application/octet-stream";
    attachmentPart.setDataHandler(new DataHandler(fileDataSource));
    attachmentPart.setFileName(filename);
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messagePart);
    multipart.addBodyPart(attachmentPart);
    message.setContent(multipart);
    Transport.send(message);
    } catch (MessagingException e) {
    e.printStackTrace();
    private class SMTPAuthenticator extends javax.mail.Authenticator {
    @Override
    public PasswordAuthentication getPasswordAuthentication() {
    String username = SMTP_AUTH_USER;
    String password = SMTP_AUTH_PWD;
    return new PasswordAuthentication(username, password);
    }I will appreciate your help to solve this situation.
    Regards,

    bshannon wrote:
    Are you sure you're using the Sun implementation of JavaMail on RedHat? Some versions of
    Linux come with the Gnu version of JavaMail included, which might behave differently.
    If you turn on session debugging, what does the protocol trace show?
    Are you sure you're sending the same file in all cases?
    Are you sure the file upload is complete before you send the file?Are you sure you're using the Sun implementation of JavaMail on RedHat?
    Yes I am using JavaMail 1.4 from SUN.
    If you turn on session debugging, what does the protocol trace show?
    Yes. Below you will find the protocol trace.
    Are you sure you're sending the same file in all cases?
    Yes I am sure.
    Are you sure the file upload is complete before you send the file?
    Good point. I will check it out!
    Protocol Trace output:
    Grabando archivo en disco...
    DEBUG: setDebug: JavaMail version 1.4.1
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: trying to connect to host "168.243.220.232", port 25, isSSL false
    220 SMTP IM2 Proxy Server Ready
    DEBUG SMTP: connected to host "168.243.220.232", port: 25
    EHLO web2.enteoperador.org
    250-ESMTP Server Ready
    250-SIZE 0
    250-DSN
    250-AUTH LOGIN
    250-AUTH=LOGIN
    250-STARTTLS
    250 TLS
    DEBUG SMTP: Found extension "SIZE", arg "0"
    DEBUG SMTP: Found extension "DSN", arg ""
    DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
    DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
    DEBUG SMTP: Found extension "STARTTLS", arg ""
    DEBUG SMTP: Found extension "TLS", arg ""
    DEBUG SMTP: Attempt to authenticate
    AUTH LOGIN
    334 VXNlcm5hbWU6
    c3ZhbGxl
    334 UGFzc3dvcmQ6
    dmFsZXJpYW1pYW1vcg==
    235 Authenticated successfully
    DEBUG SMTP: use8bit false
    MAIL FROM:<[email protected]>
    250 +OK Sender OK
    RCPT TO:<[email protected]>
    250 +OK Recipient OK
    DEBUG SMTP: Verified Addresses
    DEBUG SMTP:   [email protected]
    DATA
    354 Start mail input, end with "<CR><LF>.<CR><LF>"
    Date: Fri, 26 Sep 2008 17:47:18 -0600 (CST)
    From: [email protected]
    To: [email protected]
    Message-ID: <[email protected]>
    Subject: Sendit from linux
    MIME-Version: 1.0
    Content-Type: multipart/mixed;
            boundary="----=_Part_0_28970806.1222472838992"
    ------=_Part_0_28970806.1222472838992
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    This is a important message with attachment
    ------=_Part_0_28970806.1222472838992
    Content-Type: application/octet-stream;
            name="//www//tomcat//upload//oper-hon//HON-SOLMANT28AGO08.pdf"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment;
            filename="//www//tomcat//upload//oper-hon//HON-SOLMANT28AGO08.pdf"
    JVBERi0xLjANCg0KMSAwIG9iag0KPDwgL1R5cGUgL0NhdGFsb2cgL1BhZ2VzIDIgMCBSID4+DQpl
    bmRvYmoNCg0KMiAwIG9iag0KPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFsgMyAwIFIgXSAvQ291bnQg
    MSA+Pg0KZW5kb2JqDQoNCjMgMCBvYmoNCjw8IC9UeXBlIC9QYWdlIC9QYXJlbnQgMiAwIFIgL01l
    77+9DC/vv73vv71YYO+/vVsMF20t77+977+9Nkg777+9bitg77+9KO+/ve+/ve+/ve+/ve+/vXw1
    X++/vW8J77+977+9NQknfu+/vQgw77+9TX1177+9YSwS77+9
    ------=_Part_0_28970806.1222472838992--
    250 +OK message queued for delivery.
    QUIT
    221 Service closing transmission channel closing connection

  • Error Occurred while sending mail through gmail account

    Hello,
    I am writing 1 demo appln which will send a mail from my gmail account. It will show error like "javax.mail.MessagingException: 530 5.5.1 Authentication Required f77sm3109311pyh"
    Here is Code : -
    package demo;
    import java.util.Properties;
    import javax.mail.Address;
    import javax.mail.Authenticator;
    import javax.mail.Message;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    public class Demo {
         * @param args
         public static void main(String[] args) {
              try
              Properties properties=System.getProperties();
              properties.put("mail.smtp.host","smtp.gmail.com");
              properties.put("mail.smtp.auth","true");
              properties.put("mail.from","[email protected]");
              properties.put("mail.smtp.port","465");
              properties.put("mail.smtp.starttls.enable","true");          
              properties.put("mail.smtp.socketFactory.port", "465");
              properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
              properties.put("mail.smtp.socketFactory.fallback", "false");
              Authenticator auth = new PopupAuthenticator();
              Session session = Session.getDefaultInstance(properties,auth);                    
              session.setDebug(true);     
    //          Define message
              MimeMessage message = new MimeMessage(session);
              message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
              message.setSubject("Hello JavaMail");
              message.setText("Welcome to JavaMail");          
              message.saveChanges();
              Address address[] = message.getAllRecipients();
              Address a1 = address[0];
              System.out.println("Recipient : "+a1.toString());          
              Transport.send(message, message.getAllRecipients());
              catch(Exception e){e.printStackTrace();}
    and code for PopupAuthenticator :-
    package demo;
    import javax.mail.Authenticator;
    import javax.mail.PasswordAuthentication;
    import javax.swing.*;
    import java.util.StringTokenizer;
    public class PopupAuthenticator extends Authenticator
         public PopupAuthenticator()
              System.out.println("In Auth");
    public PasswordAuthentication getPasswordAuthentication()
    String username, password;
    String result = JOptionPane.showInputDialog("Enter 'username,password'");
    StringTokenizer st = new StringTokenizer(result, ",");
    username = st.nextToken();
    password = st.nextToken();
    return new PasswordAuthentication(username, password);
    But when i run this code i never get popup window asking for username/password and it throws follwing exception
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         javax.mail.MessagingException: 530 5.5.1 Authentication Required f77sm3109311pyh
         at javax.mail.Transport.send0(Transport.java:204)
         at javax.mail.Transport.send(Transport.java:88)
         at demo.Demo.main(Demo.java:66)
    may i know wats wrong wid my code? I am confussed about when getPasswordAuthentication () method will call?
    please reply me at [email protected]
    thnx in advance ..
    -Sushrut

    Hi bshannon ,
    Thnx ..
    I have removed the popup code from my PopUpAuthanticer.java file
    But i got similar error ....
    Here is Debug message : -
    In Auth
    Recipient : [email protected]
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG: SMTPTransport trying to connect to host "smtp.gmail.com", port 465
    DEBUG SMTP RCVD: 220 mx.google.com ESMTP y78sm4251719pyg
    DEBUG SMTP SENT: helo sushrutr
    DEBUG SMTP RCVD: 250 mx.google.com at your service
    DEBUG: SMTPTransport connected to host "smtp.gmail.com", port: 465
    DEBUG SMTP SENT: mail from: <[email protected]>
    DEBUG SMTP RCVD: 530 5.5.1 Authentication Required y78sm4251719pyg
    DEBUG SMTP SENT: quit
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         javax.mail.MessagingException: 530 5.5.1 Authentication Required y78sm4251719pyg
         at javax.mail.Transport.send0(Transport.java:204)
         at javax.mail.Transport.send(Transport.java:88)
         at demo.Demo.main(Demo.java:53)
    can u please tell me when getPasswordAuthentication() will call ? and who is going to call this ...
    Thnx in advance ...

  • How can I get Read receipt using DSN?

    Hi all,
    I can able to get the Delivered/Undelivered receipt using following code, but am not able to receive Read receipt.
    Am sure I need to add few lines to get that Read receipt. But am not get exact code to achieve that. Already I have searched lot here.Still not get exact code to read receipt using DSN.
    Following is a code, Which am using to get Delivered/Undelivered receipt successfully:
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class testMail {
        public static void main(String args[]) throws Exception {
            String host = "172.15.4.12";
            String from = "[email protected]";
            String to = "[email protected]";
            String dsn = "SUCCESS,FAILURE,DELAY ORCPT=rfc822;" + from;
            // Get system properties
            Properties properties = System.getProperties();
            // Setup mail server
           properties.setProperty("mail.smtp.host", host);
           properties.put("mail.smtp.dsn.notify", dsn);
            // Get the default Session object.
            Session session = Session.getDefaultInstance(properties);
            // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage(session);
            // Set the RFC 822 "From" header field using the
            // value of the InternetAddress.getLocalAddress method.
            message.setFrom(new InternetAddress(from));
            // Add the given addresses to the specified recipient type.
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            // Set the "Subject" header field.
            message.setSubject("hi..!");
            // Sets the given String as this part's content,
            // with a MIME type of "text/plain".
            message.setText("Delivered:");
            // Send message
            Transport.send(message);
             System.out.println("Message Send.....");
    }with above code,I can able to get Delivered/Undelivered receipt.
    I need code to get the Read receipt by using Java mail API.
    Already I did lot of search in google and got weird.
    Thats why I post here.If anybody have the sample code to do this pls., share here..this helpful to lot.
    Thanks in advance.

    bshannon wrote:
    Please read [RFC 3798|http://www.ietf.org/rfc/rfc3798.txt].
    You'll need to set the Disposition-Notification-To header using the setHeader method.Hi I got the solution with below code. I add just one line code in my previous code.Now its work fine. But As bshannon replied me, here am not used setHeader method.I have used addHeader method.
    below my code:
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class testMail {
        public static void main(String args[]) throws Exception {
            String host = "172.16.3.13";
            String from = "[email protected]";
            String to = "[email protected]";
            String dsn = "SUCCESS,FAILURE,DELAY ORCPT=rfc1891;" + to;
            // Get system properties
            Properties properties = System.getProperties();
            // Setup mail server
           properties.setProperty("mail.smtp.host", host);
           properties.put("mail.smtp.dsn.notify", dsn);
            // Get the default Session object.
            Session session = Session.getDefaultInstance(properties);
            // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage(session);
                   // value of the InternetAddress.getLocalAddress method.
            message.setFrom(new InternetAddress(from));
            // Add the given addresses to the specified recipient type.
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
           //below one line code I added to get read receipt mail.
            *message.addHeader("Disposition-Notification-To", "[email protected]");*   
        // Set the "Subject" header field.
            message.setSubject("hi..!");
            // Sets the given String as this part's content,
            // with a MIME type of "text/plain".
            message.setText("Hi this is test mail:");
            // Send message
            Transport.send(message);
             System.out.println("Message Send.....");
    Hi bshanon thanks for your kind reply

  • Some WLST Goodies

    In this post we will use WLST to create a WebLogic domain (cluster, web server, resources, security and deployment). WLST is a scripting language, which can be used to create, monitor and manage domains. WLST is based on Jython and provides next to the default Jython functionality, functions which are WebLogic Server specific. WLST can be used in two ways: online and offline. The offline mode has no connection with the admin server, the online mode has. The offline mode can be used for creating domains. To configure the created domain we must connect to the admin server. WLST online is a Java Management Extensions (JMX) client, which communicates with the server's managed beans collections. A managed bean is a Java object that provides an interface for a particular resource. An overview of the available managed beans can be found here.
    Before we start walking through the individual configuration steps, we define a few helpful parameters
    beahome = '/home/oracle/bea';
    linux = true;
    adminusername = 'username';
    adminpassword = 'password';
    servername = 'AdminServer';
    domainname = 'ScriptDomain';
    pathseparator = '/';
    if not linux:
         pathseparator = '\\';
    # set paths
    domaintemplate = beahome + pathseparator + 'wlserver_10.3' + pathseparator + 'common' + pathseparator + 'templates' + pathseparator + 'domains' + pathseparator + 'wls.jar';
    domainlocation = beahome + pathseparator + 'user_projects' + pathseparator + 'domains' + pathseparator + domainname;
    nodemanagerhomelocation = beahome + pathseparator + 'wlserver_10.3' + pathseparator + 'common' + pathseparator + 'nodemanager';
    jvmlocation = beahome + pathseparator + 'jrockit_160_05_R27.6.2-20';
    jsfrilibrary = beahome + pathseparator + 'wlserver_10.3' + pathseparator + 'common' + pathseparator + 'deployable-libraries' + pathseparator + 'jsf-ri-1.1.1.war';
    trinidadlibrary = beahome + pathseparator + 'wlserver_10.3' + pathseparator + 'common' + pathseparator + 'deployable-libraries' + pathseparator + 'trinidad.war';
    coherencelibrary = beahome + pathseparator + 'wlserver_10.3' + pathseparator + 'coherence' + pathseparator + 'coherence-web-spi.war';
    videotheekproxypath = beahome + pathseparator + 'deploy' + pathseparator + 'videotheekproxy' + pathseparator + 'VideotheekProxy.war';
    videotheekproxyplanpath = beahome + pathseparator + 'deploy' + pathseparator + 'videotheekproxy' + pathseparator + 'Plan.xml';
    videotheekpath = beahome + pathseparator + 'deploy' + pathseparator + 'videotheek' + pathseparator + 'Videotheek.ear';
    videotheekplanpath = beahome + pathseparator + 'deploy' + pathseparator + 'videotheek' + pathseparator + 'Plan.xml';
    Create a domain
    By using a domain template, we can create a new domain. Some default templates are available in the directory: <middleware-home>/wlserver_10.3/common/templates/domains. In the example, we use the template wls.jar
    createDomain(domaintemplate, domainlocation, adminusername, adminpassword);
    WLST online
    Before we are able to create resources, we must first connect to the admin server
    print 'START NODE MANAGER';
    startNodeManager(verbose='true', NodeManagerHome=nodemanagerhomelocation, ListenPort='5556', ListenAddress='localhost');
    print 'CONNECT TO NODE MANAGER';
    nmConnect(adminusername, adminpassword, 'localhost', '5556', domainname, domainlocation, 'ssl');
    print 'START ADMIN SERVER';
    nmStart(servername);
    print 'CONNECT TO ADMIN SERVER';
    connect(adminusername, adminpassword);
    Edit mode
    Changes are made in the WLST edit mode
    print 'START EDIT MODE';
    edit();
    startEdit();
    Create server environment
    First, we create a machine
    print 'CREATE MACHINE: VIDEOTHEEKMACHINE';
    videotheekMachine = cmo.createUnixMachine('VideotheekMachine');
    videotheekMachine.setPostBindUIDEnabled(true);
    videotheekMachine.setPostBindUID('oracle');
    videotheekMachine.setPostBindGIDEnabled(true);
    videotheekMachine.setPostBindGID('oracle');
    videotheekMachine.getNodeManager().setNMType('ssl');The variable cmo contains the current management object. (The methode ls() provides the functionality to print a tree containing all child objects of the current management object. By using cd('naamManagementBean') we can change the current management object.) Note that, in the example above a machine object of type MachineMBean is created. This management bean has related management beans such a NodeManager of type NodeManagerMBean. Using the method getNodeManager() we obtain an instance of this bean. By using accessors such as setNMType(), we can change the node manager type.
    In a same manner, we create a cluster
    print 'CREATE CLUSTER: VIDEOTHEEKCLUSTER';
    videotheekCluster = cmo.createCluster('VideotheekCluster');
    videotheekCluster.setClusterMessagingMode('unicast');
    videotheekCluster.setWeblogicPluginEnabled(true);In the next step, we create a managed server and add this to the machine and cluster
    print 'CREATE MANAGED SERVER: VIDEOTHEEKSERVER1';
    videotheekServer1 = cmo.createServer('VideotheekServer1');
    videotheekServer1.setListenPort(7002);
    videotheekServer1.setAutoRestart(true);
    videotheekServer1.setAutoKillIfFailed(true);
    videotheekServer1.setRestartMax(2);
    videotheekServer1.setRestartDelaySeconds(10);
    videotheekServer1.getServerStart().setJavaHome(jvmlocation);
    videotheekServer1.getServerStart().setJavaVendor('Oracle');
    videotheekServer1.getServerStart().setArguments('-Xms128m -Xmx256m -Xns64m -Xgcprio:pausetime');
    print 'ADD MANAGED SERVERS TO CLUSTER';
    videotheekServer1.setCluster(videotheekCluster);
    print 'ADD MANAGED SERVERS TO MACHINE';
    videotheekServer1.setMachine(videotheekMachine);Creating the web server is identical, except that we do not add this server to the cluster
    print 'CREATE MANAGED SERVER: VIDEOTHEEKWEBSERVER';
    videotheekWebServer = cmo.createServer('VideotheekServer2');
    videotheekWebServer.setListenPort(7004);
    videotheekWebServer.setAutoRestart(true);
    videotheekWebServer.setAutoKillIfFailed(true);
    videotheekWebServer.setRestartMax(2);
    videotheekWebServer.setRestartDelaySeconds(10);
    videotheekWebServer.getServerStart().setJavaHome(jvmlocation);
    videotheekWebServer.getServerStart().setJavaVendor('Oracle');
    videotheekWebServer.getServerStart().setArguments('-Xms128m -Xmx128m -Xns32m -Xgcprio:throughput');
    print 'ADD MANAGED SERVER TO MACHINE';
    videotheekWebServer.setMachine(videotheekMachine);
    Save and activate changes
    Changes can be save and activated as follows
    save();
    activate(block='true');
    Create a Java messaging environment
    First, we create a file store to save messages
    videotheekFileStore = cmo.createFileStore('VideotheekFileStore');
    targets = videotheekFileStore.getTargets();
    targets.append(videotheekServer1);
    videotheekFileStore.setTargets(targets);The methode getTargets() returns a management bean of type TargetMBean. This management bean represents a targets list. All management beans that represent resources implement this TargetMBean. Targets can only be servers or clusters. The targets list is a Jython array and thus can be manipulated as such. The methode append() adds a target to the list, in this case: VideotheekServer1.
    Next, we create a JMS Server and map this to the filestore
    videotheekJMSServer = cmo.createJMSServer('VideotheekJMSServer');
    videotheekJMSServer.setPersistentStore(videotheekFileStore);
    videotheekJMSServer.setTargets(targets);Note that we target the JMS Server to the same target as the filestore. A JMS module can be created as follows
    videotheekModule = cmo.createJMSSystemResource('VideotheekModule');
    targets.remove(videotheekServer1);
    targets.append(videotheekCluster);
    videotheekModule.setTargets(targets);The JMS Module is targeted to the cluster (note that we first remove the managed server from the target list). Using a sub deployment all the resources in the JMS module are deployed to the JMS Server
    videotheekModule.createSubDeployment('VideotheekSubDeployment');
    videotheekSubDeployment = videotheekModule.lookupSubDeployment('VideotheekSubDeployment');
    targets.remove(videotheekCluster);
    targets.append(videotheekJMSServer);
    videotheekSubDeployment.setTargets(targets);JMS Resources, such as Connection Factories and Queues can be created as follows
    jmsResource = videotheekModule.getJMSResource();
    jmsResource.createConnectionFactory('VideotheekConnectionFactory');
    videotheekConnectionFactory = jmsResource.lookupConnectionFactory('VideotheekConnectionFactory');
    videotheekConnectionFactory.setJNDIName('jms/ConnectionFactory');
    videotheekConnectionFactory.setSubDeploymentName('VideotheekSubDeployment');
    jmsResource.createQueue('VideotheekQueue');
    videotheekQueue = jmsResource.lookupQueue('VideotheekQueue');
    videotheekQueue.setJNDIName('jms/VideotheekQueue');
    videotheekQueue.setSubDeploymentName('VideotheekSubDeployment');
    videotheekQueue.getDeliveryParamsOverrides().setRedeliveryDelay(100);
    videotheekQueue.getDeliveryFailureParams().setRedeliveryLimit(5);
    videotheekQueue.getDeliveryFailureParams().setExpirationPolicy('Log');
    videotheekQueue.getDeliveryFailureParams().setExpirationLoggingPolicy('%headers%);
    videotheekQueue.getMessageLoggingParams().setMessageLoggingEnabled(true);
    videotheekQueue.getMessageLoggingParams().setMessageLoggingFormat('%headers%');In the example above, the management bean JMSResource is resolved. The factory method createConnectionFactory() is used to create a connection factory. Note that this mehtod does not return an instance of connection factory. Using the method lookupConnectionFactory() we cobtain the desired instance. Next, we modify some connection factory parameters. The creation of a queue goes along the same lines.
    Create a Connection Pool
    First, we create a data source
    videotheekDataSource = cmo.createJDBCSystemResource('VideotheekDataSource');
    targets.remove(videotheekJMSServer);
    targets.append(videotheekCluster);
    videotheekDataSource.setTargets(targets);
    jdbcResource = videotheekDataSource.getJDBCResource();
    jdbcResource.setName('VideotheekDataSource');
    names = ['jdbc/exampleDS'];
    dataSourceParams = jdbcResource.getJDBCDataSourceParams();
    dataSourceParams.setJNDINames(names);
    dataSourceParams.setGlobalTransactionsProtocol('none');Next, we modify some driver parameters, linked to this data source
    driverParams = jdbcResource.getJDBCDriverParams();
    driverParams.setUrl('jdbc:oracle:thin:@hostname:1521:sid');
    driverParams.setDriverName('oracle.jdbc.OracleDriver');
    driverParams.setPassword('password');
    driverProperties = driverParams.getProperties();
    driverProperties.createProperty('user');
    userProperty = driverProperties.lookupProperty('user');
    userProperty.setValue('username');The property user is specific for the used driver. This property can be added by using the JDBCPropertiesBean. Finally, we modify some connection pool parameters
    connectionPoolParams = jdbcResource.getJDBCConnectionPoolParams();
    connectionPoolParams.setTestTableName('SQL SELECT 1 FROM DUAL');
    connectionPoolParams.setConnectionCreationRetryFrequencySeconds(100);
    Create Mail Session
    The final resource we create is a mail session
    videotheekMailSession = cmo.createMailSession('VideotheekMailSession');
    videotheekMailSession.setTargets(targets);
    videotheekMailSession.setJNDIName('mail/VideotheekMailSession');
    import java.util.Properties;
    properties = java.util.Properties();
    properties.put('mail.smtp.password','password');
    properties.put('mail.smtp.port','25');
    properties.put('mail.transport.protocol','smtp');
    properties.put('mail.smtp.host','mail.some-company.com');
    properties.put('mail.smtp.user','username');
    properties.put('mail.to','[email protected]');
    properties.put('mail.from','[email protected]');
    videotheekMailSession.setProperties(properties);To add properties, we use the module java.util.Properties. A properties variable is instantiated using java.util.Properties(). As a final step this properties variable is added to the management bean instance.
    Security
    Creating a security realm
    securityConfiguration = cmo.getSecurityConfiguration();
    securityConfiguration.createRealm('VideotheekRealm');
    realm = securityConfiguration.lookupRealm('VideotheekRealm');
    realm.createAuthenticationProvider('weblogic.security.providers.authentication.DefaultAuthenticator');
    authenticator = realm.lookupAuthenticationProvider('DefaultAuthenticator');
    authenticator.setControlFlag('optional');
    realm.createAuthorizer('weblogic.security.providers.authorization.DefaultAuthorizer');
    realm.createAdjudicator('weblogic.security.providers.authorization.DefaultAdjudicator');
    realm.createRoleMapper('weblogic.security.providers.authorization.DefaultRoleMapper');
    realm.createCredentialMapper('weblogic.security.providers.credentials.DefaultCredentialMapper');
    realm.createCertPathProvider('weblogic.security.providers.pk.WebLogicCertPathProvider');By using WLST it is not possible to set the created certpath provider as the current builder. It is also not possible to set a created security realm as the default realm. To do this we must resort to the admin console.
    Adding users and groups to the default realm
    print 'START SERVER CONFIG';
    serverConfig();
    print 'ADD USERS AND GROUPS TO DEFAULT SECURITY REALM';
    securityRealm = cmo.getSecurityConfiguration().getDefaultRealm();
    authProvider = securityRealm.lookupAuthenticationProvider('DefaultAuthenticator');
    authProvider.createUser('anemployee', 'welcome1', 'an employee of the videotheek');
    authProvider.createUser('amanager', 'welcome1', 'a manager of the videotheek');
    authProvider.createGroup('employees', 'employee group of the videotheek');
    authProvider.createGroup('managers', 'manager group of the videotheek');
    authProvider.addMemberToGroup('employees', 'anemployee');
    authProvider.addMemberToGroup('managers', 'amanager');Changes concerning security must be performed in the serverConfig environment. Now we are able to obtain an instance of the default realm. Using this instance, the authentication provider can be looked up, to which users and groups are added. It is also possible to add groups or users to defined roles, for example,
    sr = cmo.getSecurityConfiguration().getDefaultRealm();
    rm = sr.lookupRoleMapper('XACMLRoleMapper');
    expr = rm.getRoleExpression(None,'Admin');
    rm.setRoleExpression(None,'Admin',expr+'|Usr(employee)');
    rm.setRoleExpression(None,'Anonymous','Usr(employee)|Grp(everyone)');
    rm.setRoleExpression(None,'Anonymous','Usr(employee)&Grp(everyone)');
    Deployment
    First, we start the managed servers
    print 'START MANAGED SERVERS';
    start('VideotheekWebServer','Server');
    start('VideotheekCluster','Cluster');Next, we deploy the libraries and the applications
    print 'DEPLOY LIBRARIES';
    deploy('jsf-ri', path=jsfrilibrary, targets='VideotheekCluster', libraryModule='true');
    deploy('trinidad', path=trinidadlibrary, targets='VideotheekCluster', libraryModule='true');
    deploy('coherence-web-spi', path=coherencelibrary, targets='VideotheekCluster', libraryModule='true');
    print 'START EDIT MODE';
    edit();
    startEdit();
    print 'CHANGE DEPLOYMENT ORDER OF DEPLOYED LIBRARIES';
    libraries = cmo.getLibraries();
    for library in libraries:
        library.setDeploymentOrder(1);
    print 'SAVE AND ACTIVATE CHANGES';
    save();
    activate(block='true');The attribute libaryModule indicates, we are dealing with a library deployment. To deploy some applications we can use
    print 'DEPLOY PROXY SERVLET TO MANAGED WEB SERVER';
    deploy('VideotheekProxy', path=videotheekproxypath, targets='VideotheekWebServer', planPath=videotheekproxyplanpath, securityModel='Advanced');
    print 'DEPLOY APPLICATION VIDEOTHEEK TO CLUSTER';
    deploy('Videotheek', path=videotheekpath, targets='VideotheekCluster', planPath=videotheekplanpath, securityModel='Advanced');The attribuut planPath points to the location of the deployment plans, which were created before hand.
    Running a WLST script
    Open a command shell and set the WebLogic environment by running the command: source ./setWLSEnv.sh (or the short version: . ./setWLSEnv.sh). The script setWLSEnv.sh is located in the directory <middleware-home>/wlserver_10.3/server/bin. To run a WLST script we can something like: java weblogic.WLST bea/path_to_script/ScriptName.py

    Shameless plug.
    And if you really want to feel good about ordering, please order Lightroom via the LightroomExtra.com home page and you will help me pay for all the bandwidth.
    Sid
    The LightroomExtra home page is right here.

  • Problem with Simple MailSend Program

    Pls, help, I am new to the JavaMailApi. My program is trying :) to connect to MailServer via SMTP and SSL protocol. It does not work. I turned on Session debbuging. I got
    "DEBUG SMTP: trying to connect to host "smtp.googlemail.com", port 465, isSSL false".
    what does it mean? Maybe I forgot to set up some properties?
    String host = "smtp.googlemail.com";
    properties.put("mail.host", host);
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.port", "465");
    properties.put("mail.debug", "true");
    properties.put("mail.smtp.starttls.enable", "true");
    Thx.

    Port 465 is usually not "SMTP with STARTTLS", it's usually
    "SMTP over SSL". YOu probably want to use the "smtps"
    protocol. See SSLNOTES.txt that's included with JavaMail
    for instructions on how to switch the default. Don't forget to
    adjust any property settings as well (e.g., use "mail.stmps.auth"
    instead of "mail.stmp.auth").

  • Code for mailing from behing a proxy using Authentication

    Dear friends,
    I have found several requests regarding the mailing from behing a firewall/proxy with Authentication.. So here is the entire code for the same..
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    import java.util.*;
    import javax.mail.*;
    import javax.mail.event.*;
    import javax.mail.internet.*;
    public class MailClient extends Frame{
    static String mailHost="proxyAddress";
    public MailClient() {
    public static void main(String[] args) {
    Properties properties=new Properties();
    properties.put("mail.smtp.host",mailHost);
    properties.put("mail.smtp.auth","true");
    Session session=Session.getDefaultInstance(properties,new MyAuthentication());
    try{
    Message msg=new MimeMessage(session);
    InternetAddress address[]={new InternetAddress("toAddress1.domain.com")};
    msg.setRecipients(Message.RecipientType.TO,address);
    msg.setSubject("Test Mail");
    msg.setFrom(new InternetAddress("[email protected]"));
    msg.setContent("Please reply.. This is a java mail using Authentication
    technique..","text/plain");
    Transport transport=session.getTransport("smtp");
    transport.connect();
    transport.sendMessage(msg,msg.getAllRecipients());
    }catch(Exception e){e.printStackTrace();}
    Hope this helps..
    regards Stallon
    class MyAuthentication extends Authenticator{
    public PasswordAuthentication getPasswordAuthentication(){
    return new PasswordAuthentication("userName","password");
    }

    Hi stallon,
    Thanks for ur reply.Actually my application is at server2. I have an account in server1 and sending mail from server2. server1 requires authentication to send it to server3. Though we provide it is not accepting.There no errors while execution but mail couldn't be send.
    Please help me as soon as possible.
    Thanks in advance,
    bdurvasula
    //debug code.
    DEBUG: getProvider() returning
    javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
    Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG: SMTPTransport trying to connect to host
    "host", port 25
    DEBUG SMTP RCVD: 220 host ESMTP
    server (Netscape Messaging Server - Version 3.6)
    ready
    Thu, 21 Jun 2001 14:23:15 +0800
    DEBUG: SMTPTransport connected to host
    "host", port: 25
    DEBUG SMTP SENT: EHLO rao
    DEBUG SMTP RCVD: 250-host
    250-HELP
    250-EXPN
    250-ETRN
    250-PIPELINING
    250-DSN
    250 AUTH=LOGIN
    DEBUG SMTP SENT: MAIL FROM:<[email protected]>
    DEBUG SMTP RCVD: 250 Sender
    <[email protected]>
    Ok
    DEBUG SMTP SENT: RCPT TO:<[email protected]>
    DEBUG SMTP RCVD: 250 Recipient
    <[email protected]> Ok
    Verified Addresses
    [email protected]
    DEBUG SMTP SENT: DATA
    DEBUG SMTP RCVD: 354 Ok Send data ending with
    <CRLF>.<CRLF>
    DEBUG SMTP SENT:
    DEBUG SMTP RCVD: 250 Message received:
    7745C8DA90B.AAA27D7
    DEBUG SMTP SENT: QUIT
    //now i am sending the mail that was sent by my server
    This Message was undeliverable due to the following
    reason:
    Your message was not delivered because the
    destination
    computer
    refused to accept it. The error message generated
    by
    the server
    is reproduced below.
    Non-local addressee. We do not relay!
    Please reply to Postmaster@mailserver .if you feel
    this message to be in error.Thanks once again
    bdurvasula

  • Help with bug fix

    hey peeps i am running the following code to call a seperate gui from a seperate call but i get this error what does it mean? and how can i fix it
    C:\Documents and Settings\suresh\Desktop\ass\Mailc.java:107: non-static method setVisible(boolean) cannot be referenced from a static context
    Send.setVisible(true);
    public void actionPerformed(ActionEvent e)
    if (ac.equals("Open")){
              Send = new Send();          
             Send.setVisible(true);
        }

    this is the class i'm trying to call
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    //import javax.mail.*;
    //import javax.mail.event.*;
    //import javax.mail.internet.*;
    public class Send extends Frame {
    String mailHost = "smtp.ntlworld.com";
    Label toLabel = new Label("To:");
    Label fromLabel = new Label("From:");
    Label subjectLabel = new Label("Subject:");
    Label contentLabel = new Label("Content:");
    Label statusLabel = new Label("Status:");
    TextField destination = new TextField();
    TextField source = new TextField();
    TextField subject = new TextField();
    TextArea content = new TextArea();
    Button send = new Button("Send Message");
    TextArea status = new TextArea();
    public static void main(String args[]){
      Send app = new Send();
    public Send() {
      super("Send");
      setup();
      addWindowListener(new WindowEventHandler());
      setSize(550,450);
      show();
    void setup() {
      setupMenuBar();
      layoutComponents();
      send.addActionListener(new ButtonHandler());
    void setupMenuBar() {
      MenuBar menuBar = new MenuBar();
      Menu fileMenu = new Menu("File");
      MenuItem fileExit = new MenuItem("Exit");
      fileExit.addActionListener(new MenuItemHandler());
      fileMenu.add(fileExit);
      menuBar.add(fileMenu);
      setMenuBar(menuBar);
    void layoutComponents() {
      int x = 10;
      int y = 50;
      // Set bounds
      toLabel.setBounds(x,y,50,25);
      destination.setBounds(x+70,y,300,25);
      fromLabel.setBounds(x,y+40,50,25);
      source.setBounds(x+70,y+40,300,25);
      subjectLabel.setBounds(x,y+80,50,25);
      subject.setBounds(x+70,y+80,300,25);
      contentLabel.setBounds(x,y+120,50,25);
      content.setBounds(x+70,y+120,300,100);
      statusLabel.setBounds(x,y+240,50,25);
      status.setBounds(x+70,y+240,300,100);
      send.setBounds(400,y,100,30);
      // Add components
      add(toLabel);
      add(destination);
      add(send);
      add(fromLabel);
      add(source);
      add(subjectLabel);
      add(subject);
      add(contentLabel);
      add(content);
      add(statusLabel);
      add(status);
      add(new Label(""));
    void sendMessage() {
      Properties properties = new Properties();
      properties.put("mail.smtp.host",mailHost);
      properties.put("mail.from",source.getText());
      //Session session = Session.getInstance(properties, null);
      try {
      // Message message = new MimeMessage(session);
      // InternetAddress[] address =
      //  {new InternetAddress(destination.getText())};
      // message.setRecipients(Message.RecipientType.TO, address);
      // message.setFrom(new InternetAddress(source.getText()));
      // message.setSubject(subject.getText());
      // message.setContent(content.getText(),"text/plain");
      // Transport transport = session.getTransport(address[0]);
      // transport.addConnectionListener(new ConnectionHandler());
      // transport.addTransportListener(new TransportHandler());
      // transport.connect();
      // transport.sendMessage(message,address);
      }catch(Exception e){
       status.setText(e.toString());
    // class ConnectionHandler extends ConnectionAdapter {
    // public void opened(ConnectionEvent e) {
      // status.setText("Connection opened.");
    // public void disconnected(ConnectionEvent e) {
    //  status.setText("Connection disconnected."); 
    // public void closed(ConnectionEvent e) {
      // status.setText("Connection closed."); 
    //class TransportHandler extends TransportAdapter {
    // public void messageDelivered(TransportEvent e) {
      // status.setText("Message delivered."); 
    // public void messageNotDelivered(TransportEvent e) {
      // status.setText("Message NOT delivered."); 
    // public void messagePartiallyDelivered(TransportEvent e) {
    //  status.setText("Message partially delivered."); 
    class ButtonHandler implements ActionListener {
      public void actionPerformed(ActionEvent ev){
       String s=ev.getActionCommand();
    //  if(s.equals("Send Message")) sendMessage();
    class MenuItemHandler implements ActionListener {
      public void actionPerformed(ActionEvent ev){
       String s=ev.getActionCommand();
       if(s=="Exit"){
        System.exit(0);
    class WindowEventHandler extends WindowAdapter {
      public void windowClosing(WindowEvent e){
       System.exit(0);
    //

  • Succes sending mail with yahoo stmp server =) but still more questions

    why i can not instantiate an Authenticator object with new, i have to do this:
    Authenticator object= new Authenticator(){ code...}
    or create a new class extends from Authenticator, how does authenticator works or why it doesnt have methods or constructors :s...

    hi echo, bshannon
    thanks for your helps.
    first to echo : i have tried with yahoo.
    ihave registered by yahoo and i have used the code below :
    private String host="smtp.mail.yahoo.de";
    Properties properties = System.getProperties();
    properties.put("mail.smtp.host", host);
    //properties.put("mail.smtp.port", 587);
    Transport tr = session.getTransport("smtp");
    tr.connect(host, username, password);
    in last line i get en error : "530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html"
    i have check this out and i tried to make it with port 587 like above. but it doesn't go :( i use norton antivirus and disabed the checking outgoing email too but still not working!!
    do i make a mistake?? how can it be so difficult to send a mail !!!
    second to : BSHANNON
    i have tried it with my own smtp server namely "1st smtp server"
    than it didnt work. how can i set the message ID and what should i write as message iD
    thanks again

  • Can't send to emails that are out of the domain.

    I know this has been discussed in depth already. I have tried all the code examples that I have been able to find in this forum that say you should be able to send messages to email addresses that are outside the domain (Company) even if exchange server doesn't have message relaying turned on.
    None of the examples I have tried have worked. Is this just not possible? If it is, please send code examples.
    Below you will find my code.
    Properties properties = new Properties() ;
    properties.put("mail.smtp.host", hostName) ;
    properties.put("mail.smtp.auth", "true");
    // this authenticator authenticates using my username and password
    javax.mail.Authenticator auth = new PopupAuthenticator() ;
    Session session = Session.getDefaultInstance(properties, auth) ;
    MimeMessage message = new MimeMessage(session) ;
    try {
    message.setFrom(new InternetAddress(fromemail, fromname)) ;
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(to, toName)) ;
    message.setSubject(subject) ;
    message.setText(messageText) ;
    message.setSentDate(new Date());
    Transport.send(message);
    } catch (UnsupportedEncodingException e) { insertLog(e.toString()) ;  }

    I have the same problem if you have a solution please send me to [email protected], thanks.

Maybe you are looking for

  • Question about Password file

    Good afternoon, In the 2 Day DBA document it states: > When you invoke DBCA as part of the Oracle Database installation process, DBCA creates a password file with one entry: the SYS user. > I created the database using DBCA and, it must have created

  • Userexit or BADI in O4C1/O4C2

    Dear SAP Experts, I would like to implement some userexit or Badi in order to control what the user inserts in a field of the O&G transaction O4C1/O4C2. Specifically, I need to obligate the user to fill the field OIGC-TU_ID. I could not figure out so

  • Creating reports on Excel using java

    Does anyone have any idea on how to use java in creating reports on excel? Tnx in advance.

  • XSL style sheet not performing

    Hi, I'm playing around w/ the examples that came with XML SQL utility. The example works fine but does not apply the style sheet to the XML data produced from the SQL query. Is this a bug? Or is that the way its supposed to be ? I thought when you us

  • How do I import my (many) videos so iMovie separates them by the date they orig. were made?

    How do I import my (many) videos so iMovie separates them by the date they orig. were made? (Like iPhoto does with photos) But not one at a time! If that is not possible with IMovie, can iTunes do that? I want to import my videos from an external dri