How to send emails using java code

Hi,
can any give me some sample code for sending emails using java language

JavaMail quick start
jGuru: Fundamentals of the JavaMail API

Similar Messages

  • Sending Email using java code

    I am using the following code to send an email from my java servlet but the problem is, when it is on its own it works fine but as soon as I combine it with some code to submit data into a postgres database it sometimes does not perform could it be because im missing some close statements??
    //grades to submit grades starts here
                                                           String [] paramValues = req.getParameterValues("Mark");
                                                      for(int i=0; i<paramValues.length;i++)
                                                           String [] paramValues2 = req.getParameterValues("StudentExamNumber");
                                                                String Mark = paramValues;
                                                                String ExamNo = paramValues2[i];
                                                                //testing purposes
                                                                out.println("<tr><td>"+ExamNo+"</td>");
                                                                out.println("<td>"+Mark+"</td>");
                                                                try
                                                           st = conn.createStatement();
                                                           query = "SELECT StudentNo FROM STUDENTS"+WebCourse2+ " where ExamNo='"+ExamNo+"'";
                                                           rs = st.executeQuery(query);
                                                           if(rs !=null)
                                                                          while(rs.next())
                                                                               String StudentNo=rs.getString("StudentNo");
                                                                               //testing purposes
                                                                               //out.println("<td>"+StudentNo+"</td></tr>");
                                                                               here
                                                                               st4 = conn.createStatement();
                                                                     query4 = "select MAX(entryno) from STUDENTRESULTSFORCOURSE"+WebCourse2+" WHERE STUDENTNO='"+StudentNo+"'";
                                                                     rs4 = st4.executeQuery(query4);
                                                                     if(rs4 !=null)
                                                                                    while(rs4.next())
                                                                                         EntryNo = rs4.getInt(1);
                                                                                    }//end rs4 while
                                                                                    rs4.close();
                                                                               }//end rs4 if
                                                                     out.println("<tr><td>EntryNo= "+EntryNo+"</td>");
                                                                               EntryNo = EntryNo + 1;
                                                                               out.println("<td>NewEntryNo= "+EntryNo+"</td></tr>");
                                                                               //Submitting grades to database/
                                                                     st3 = conn.createStatement();
                                                                     insert = "insert into STUDENTRESULTSFORCOURSE"+WebCourse2+" (StudentNo, CourseCode, AttemptNo, ExamMark, EntryNo, EnteredBy) values ('"+StudentNo+"', '"+WebCourse2+"', 1,'"+Mark+"',"+EntryNo+",'"+WebUsername2+"')";
                                                                     st3.executeUpdate(insert);
                                                                          }//end rs while
                                                                          rs.close();
                                                                     }//end rs if
                                                                }//end try
                                                                catch (SQLException e)
                                                                     System.out.println("Error: "+e.getMessage());
                                                           }//end for loop     
                                                           //code to submit grades ends here
                                                           //code used to send email starts here
                                                           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.
                                                                     System.out.println("Connection was made. Socket is ready for use.");
                                                                     try
                                                                          // The email address that the server
                                                                          // you are using know user as.
                                                                          os.writeBytes("MAIL From: <[email protected]>\r\n");
                                                                          // Who the email is going to.
                                                                          os.writeBytes("RCPT To: <[email protected]>\r\n");
                                                                          //send a CC to:
                                                                          os.writeBytes("RCPT Cc: <[email protected]>\r\n");
                                                                          // 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("From: "+WebUsername2+"<[email protected]>\r\n");
                                                                          os.writeBytes("To: Marie <[email protected]>\r\n");
                                                                          //Again if you want to send a CC then add this.
                                                                          os.writeBytes("Cc: ProfCuthbert <[email protected]>\r\n");
                                                                          String sMessage = "ELECTRONIC ENGINEERING EXAM COLLATION SYSTEM EMAIL\n\nThe results for the following course have been submitted by the following member of staff\n\nCOURSE: "+WebCourse2+"\n\nSUBMITTED BY: "+WebUsername2+" \n\nPLEASE LOCK COURSE NOW IN ORDER TO PREVENT ANY FURTHER SUBMISSIONS TO BE MADE BY USERS.";
                                                                          os.writeBytes("Subject: A SUBMISSION HAS BEEN MADE FOR COURSE "+WebCourse2+"\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.
                                                                          // Once an OK is reached you are complete.
                                                                          String responseline;
                                                                          //for testing purposes
                                                                          //out.println(responseline = is.readLine());
                                                                          while((responseline = is.readLine())!=null)
                                                                          //for testing purposes
                                                                          //out.println("responseline= "+responseline+"<br>");
                                                                          //out.println("responseline.indexOf(Ok)= "+responseline.indexOf("Ok"));
                                                                          if(responseline.indexOf("Ok") != -1)
                                                                          break;
                                                                          if(responseline.indexOf("Ok") == -1)
                                                                          confirm=1;
                                                                          if (confirm==1)
                                                                          out.println("<br>the marks have been submitted thank you");
                                                                          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"); }
    Does anyone know what the problem is??
    thanks
    tzaf

    i close them later in the program. Ive made sure they are all closed I have a feeling that it could be coming from here....
    //code used to send email starts here
                                                           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.
                                                                     System.out.println("Connection was made. Socket is ready for use.");
                                                                     try
                                                                          // The email address that the server
                                                                          // you are using know user as.
                                                                          os.writeBytes("MAIL From: <email address>\r\n");
                                                                          // Who the email is going to.
                                                                          os.writeBytes("RCPT To: <email address>\r\n");
                                                                          //send a CC to:
                                                                          os.writeBytes("RCPT Cc: <email address>\r\n");
                                                                          // 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("From: "+WebUsername2+"<email address>\r\n");
                                                                          os.writeBytes("To: hello<email address>\r\n");
                                                                          //Again if you want to send a CC then add this.
                                                                          os.writeBytes("Cc: hello <email address>\r\n");
                                                                          String sMessage = "ELECTRONIC ENGINEERING EXAM COLLATION SYSTEM EMAIL\n\nThe results for the following course have been submitted by the following member of staff\n\nCOURSE: "+WebCourse2+"\n\nSUBMITTED BY: "+WebUsername2+" \n\nPLEASE LOCK COURSE NOW IN ORDER TO PREVENT ANY FURTHER SUBMISSIONS TO BE MADE BY USERS.";
                                                                          os.writeBytes("Subject: A SUBMISSION HAS BEEN MADE FOR COURSE "+WebCourse2+"\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.
                                                                          // Once an OK is reached you are complete.
                                                                          String responseline;
                                                                          //for testing purposes
                                                                          //out.println(responseline = is.readLine());
                                                                          while((responseline = is.readLine())!=null)
                                                                          //for testing purposes
                                                                          //out.println("responseline= "+responseline+"<br>");
                                                                          //out.println("responseline.indexOf(Ok)= "+responseline.indexOf("Ok"));
                                                                          if(responseline.indexOf("Ok") != -1)
                                                                          break;
                                                                          if(responseline.indexOf("Ok") == -1)
                                                                          confirm=1;
                                                                          if (confirm==1)
                                                                          out.println("<br>the marks have been submitted thank you");
                                                                          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"); }
                                                           //code used to send email ends here
    do i need to close is and os?
    thanks
    tzaf

  • How to send attachments using java application and outlook

    Hi ,
    I created an application in java which is as
    on the Conference Tab i can schedule a conference and with the send command on page it map all the scheduled data to outlook(with all conference details) and using outlook send option the mails are send to appropriate user.
    but now i want to modify this application such as when i use the send command from my jsp page it should attach the file that is in .vcs or .ics format for auto updation of user calender.
    can any one know how to send attachment using java application .

    Last time I checked, SMS was a service between carriers and doing SMS yourself was really tricky. Some services existed to let you do it but as I recall they wanted non-trivial money.
    However, most phone carriers provide an email-to-SMS bridge of some kind.
    So the easiest thing is just to send an email.
    That's sending from a non-phone to a phone. There's a J2ME library to send/receive SMS from/to a phone.
    However, this is from memory, and a little out of date, so I could be entirely wrong. Hope it helps anyway.

  • How to send FAX using java. (JTAPI)

    Can anybody suggest how to send FAX in Java. I've heard bout JTAPI's. but never tried it. and the sample code given is good for nothing. I want to send (not receive) FAX from my java application (Ive already tried javax.comm package, for that u need third party FAX server)
    Or is ther any other way of sending FAX except JTAPI?
    Pls comment on this.
    thanx in advance
    Ketan Malekar
    [email protected]

    To cse.mahbub:
    Are you aware that you replied to a 5 1/2 year old question?
    Please don't do that. Reply only to current questions.

  • How to send emails using JSP?

    How can i send emails using JSP? what are the things that i will need? please help me asap...thanks

    Hi,
    This works for me:
    <%
    String from = "Person"
    String to= "my-email-address;
    try{
    SmtpClient client = new SmtpClient("smtp.stuff.com");
    client.from(from);
    client.to(to);
    PrintStream message = client.startMessage();
    message.println("To: " + to);
    message.println("Subject: Sending an e-mail");
    message.println();
    message.println("Groovy :-)");
    client.closeServer();
    catch (IOException e){
    System.out.println("ERROR SENDING EMAIL: "+e);
    %>

  • Sending email using java

    Im using this code to do this, but i have a feeling that I need to close os and is is that the case? do i need to close anything else?
    thanks
    tzaf
    //code used to send email starts here
                                                           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.
                                                                     System.out.println("Connection was made. Socket is ready for use.");
                                                                     try
                                                                          // The email address that the server
                                                                          // you are using know user as.
                                                                          os.writeBytes("MAIL From: <[email protected]>\r\n");
                                                                          // Who the email is going to.
                                                                          os.writeBytes("RCPT To: <[email protected]>\r\n");
                                                                          //send a CC to:
                                                                          os.writeBytes("RCPT Cc: <[email protected]>\r\n");
                                                                          // 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("From: "+WebUsername2+"<[email protected]>\r\n");
                                                                          os.writeBytes("To: Marie <[email protected]>\r\n");
                                                                          //Again if you want to send a CC then add this.
                                                                          os.writeBytes("Cc: ProfCuthbert <[email protected]>\r\n");
                                                                          String sMessage = "ELECTRONIC ENGINEERING EXAM COLLATION SYSTEM EMAIL\n\nThe results for the following course have been submitted by the following member of staff\n\nCOURSE: "+WebCourse2+"\n\nSUBMITTED BY: "+WebUsername2+" \n\nPLEASE LOCK COURSE NOW IN ORDER TO PREVENT ANY FURTHER SUBMISSIONS TO BE MADE BY USERS.";
                                                                          os.writeBytes("Subject: A SUBMISSION HAS BEEN MADE FOR COURSE "+WebCourse2+"\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.
                                                                          // Once an OK is reached you are complete.
                                                                          String responseline;
                                                                          //for testing purposes
                                                                          //out.println(responseline = is.readLine());
                                                                          while((responseline = is.readLine())!=null)
                                                                          //for testing purposes
                                                                          //out.println("responseline= "+responseline+"<br>");
                                                                          //out.println("responseline.indexOf(Ok)= "+responseline.indexOf("Ok"));
                                                                          if(responseline.indexOf("Ok") != -1)
                                                                          break;
                                                                          if(responseline.indexOf("Ok") == -1)
                                                                          confirm=1;
                                                                          if (confirm==1)
                                                                          out.println("<br>the marks have been submitted thank you");
                                                                          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"); }
                                                           //code used to send email ends here

    any thoughts?
    thanks
    tzaf

  • Error while sending Email through Java Code in OIM

    Hi All,
    I have created a java code using tcEmailNotificationUtil, and integrated the same with the adapter.
    I am triggering this adapter when an approval process gets completed.
    As soon as the approval process gets completed my email task is triggering but the task is getting rejected.
    I have checked my system configuration for mail server settings.Everything seems working fine.
    Can you please help me in this issue how to debug?
    Thanks in advance.

    Hi,
    Here is my log file:
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SERVER] - Class/Method: QuartzWrapper/insertTaskHistory left.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/run entered.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: ReIssueAuditMessage/execute entered.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: ReIssueAuditMessage/initialize entered.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/getAttribute entered.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/getAttribute left.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/getUtility entered.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/getUtility left.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.ACCOUNTMANAGEMENT] - Class/Method: tcUtilityFactory/getRemoteUtility - Data: moUtil - Value: Thor.API.Operations.tcAuditOperationsClient
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: ReIssueAuditMessage/initialize left.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: ReIssueAuditMessage/processAllByIdentifier entered.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/isStopped entered.
    DEBUG,25 Apr 2011 10:40:00,099,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/isStopped left.
    DEBUG,25 Apr 2011 10:40:00,100,[XELLERATE.DATABASE] - select A.* from (select aud_jms_key, aud_class, identifier from aud_jms order by aud_jms_key) A where rownum <= ?
    INFO,25 Apr 2011 10:40:00,101,[XELLERATE.PERFORMANCE] - Query: DB: 1, LOAD: 0, TOTAL: 1
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/isStopped entered.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/isStopped left.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/isStopped entered.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/isStopped left.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SCHEDULER.TASK] - Class/Method: ReIssueAuditMessage/execute left.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/run left.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/isSuccess entered.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SCHEDULER.TASK] - Class/Method: SchedulerBaseTask/isSuccess left.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SERVER] - Class/Method: SchedulerTaskLocater /removeLocalTask entered.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SERVER] - Class/Method: SchedulerTaskLocater /removeLocalTask left.
    DEBUG,25 Apr 2011 10:40:00,102,[XELLERATE.SERVER] - Class/Method: QuartzWrapper/updateStatusToInactive entered.
    DEBUG,25 Apr 2011 10:40:00,104,[XELLERATE.SERVER] - Class/Method: QuartzWrapper/updateStatusToInactive left.
    DEBUG,25 Apr 2011 10:40:00,104,[XELLERATE.SERVER] - Class/Method: QuartzWrapper/updateTaskHistory entered.
    DEBUG,25 Apr 2011 10:40:00,106,[XELLERATE.SERVER] - Class/Method: QuartzWrapper/updateTaskHistory left.
    DEBUG,25 Apr 2011 10:40:00,106,[XELLERATE.SERVER] - Clearing Security Associations with thread executing Scheduled task
    DEBUG,25 Apr 2011 10:40:00,106,[XELLERATE.SERVER] - Class/Method: QuartzWrapper/run left.
    DEBUG,25 Apr 2011 10:40:00,106,[XELLERATE.SERVER] - Class/Method: QuartzWrapper/execute left.
    and I just wanted to ensure that my coding part is also fine.
    Posting the code even:
    tcDataProvider ioDatabase = new tcDataBaseClient();
    tcEmailNotificationUtil sendMail = new tcEmailNotificationUtil(ioDatabase);
    sendMail.setBody("Sample Message");
    sendMail.setSubject("subject");
    sendMail.setFromAddress("fromemailaddress");
    sendMail.sendEmail("recepient");
    Thanks in Advance.

  • Can I send email using Java from my localhost(Tomcat) with Internet connect

    Hi friends,
    Please tell me can I send email from my localhost (Tomcat) using Java when my computer is connected to Internet?
    I don't have any SMTP username or password or the like, as I found in some codes available in net.
    Please suggest and any simple code if possible.
    Please don't send me the link of JavaMail API to read.
    ---Sujoy

    Thank you for the link. Though I have not tested the provided code, I will test it.
    --Sujoy                                                                                                                                                                                       

  • How to send SMS using java

    Dear All
    How we can send SMS(Short Message Service) to mobile phones using java.
    By Registering in some sites and using that user name and password we can send SMS.
    But after some limited SMS we have to pay for further use.
    I need some thing which we can use as free.
    Can any one help me
    Thanks in Advance

    The easiest way would be to send a regular email to a Email to SMS gateway.
    Check out the list of Email to SMS gateways at http://en.wikipedia.org/wiki/SMS_gateways

  • Send Email using Java

    May i know how to send the email by using java?

    heres my final i did for java 1 last year (it was a simple email sending program:
    //java FINAL!
    import javax.swing.*;
    import java.net.URL;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class EmailProg extends JPanel implements ActionListener {
        protected JTextArea textArea;
        protected String newline = "\n";
        static final private String composemail = "compose";
        static final private String sendmail = "send";
        static final private String about = "about";
        static final private String submit = "submit";
        static final private String exit = "exit";
        JLabel lSubmit = new JLabel("Submit");
        JButton subbutton = new JButton();
        JTextArea emailfrom = new JTextArea(1,1);
        JTextArea emailto = new JTextArea(1, 1);
        JTextArea emailsubject = new JTextArea(1, 1);
        JTextArea emailmessage = new JTextArea(25, 1);
        //------BAG LAYOUT
        JLabel lFrom = new JLabel("From:");
        JTextField cFrom = new JTextField(32);
        JLabel lTo = new JLabel("To:");
        JTextField cTo = new JTextField(32);
        JFrame frame2 = new JFrame("Compose New");
        JLabel lSubject = new JLabel("Subject");
        JTextField cSubject = new JTextField(32);
        JLabel lMessage = new JLabel("Body");
        JTextArea cMessage = new JTextArea(5,32);
        //====================================
        public EmailProg() {
            super(new BorderLayout());
            //Create the toolbar.
            JToolBar toolBar = new JToolBar();
            addButtons(toolBar);
            //Create the text area used for output.  Request
            //enough space for 5 rows and 30 columns.
            textArea = new JTextArea(5, 30);
            textArea.setEditable(false);
            textArea.setText("Welcome to Jeff's email program! With this program you can compose and send emails. I hope I get a good grade on thise, and marine world finds a good use for it :-D:-D (implements really just testing the scroller!!!)");
            JScrollPane scrollPane = new JScrollPane(textArea);
            //Lay out the main panel.
            setPreferredSize(new Dimension(450, 110));
            add(toolBar, BorderLayout.NORTH);
            add(scrollPane, BorderLayout.CENTER);
        //==================================
        protected void addButtons(JToolBar toolBar) {
            JButton button = null;
            //first button
            button = makeNavigationButton("/toolbarButtonGraphics/general/ComposeMail24.gif", composemail ,"Compose new Email", "compose new");
            toolBar.add(button);
            //second button
            button = makeNavigationButton("toolbarButtonGraphics/general/SendMail24.gif", sendmail,"Send The Mail","send");
            toolBar.add(button);
            //third button
            button = makeNavigationButton("toolbarButtonGraphics/general/About24.gif", about,"About","About");
            toolBar.add(button);
            //exit button
            button = makeNavigationButton("toolbarButtonGraphics/general/Stop24.gif", exit, "Exit", "Exit");
            toolBar.add(button);
        //===================================
        protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {
            //Look for the image.
            String imgLocation = imageName;
            URL imageURL = EmailProg.class.getResource(imgLocation);
            //Create and initialize the button.
            JButton button = new JButton();
            button.setActionCommand(actionCommand);
            button.setToolTipText(toolTipText);
            button.addActionListener(this);
            if (imageURL != null) {                      //image found
                button.setIcon(new ImageIcon(imageURL));
            } else {                                     //no image found
                button.setText(altText);
                System.err.println("Resource not found: "+ imgLocation);
            return button;
        //=============================
        public void actionPerformed(ActionEvent e) {
            String cmd = e.getActionCommand();
            String description = null;
            // Handle each button.
            if (exit.equals(cmd)){
                textArea.setText("");
                description = "EXITING";
                System.exit(0);
            if (composemail.equals(cmd)) { //first button clicked
                textArea.setText("");
                description = "Write new mail.";
                composeWindow();
            } else if (sendmail.equals(cmd)) { // second button clicked
                textArea.setText("");
                description = "This button does'nt do anything yet :x";
            } else if (about.equals(cmd)) { // third button clicked
                textArea.setText("");
                description = "About this program. (See pop-up)";
                coolWindow();
            else if (submit.equals(cmd))
                if (cFrom.getText().equals("")||cTo.getText().equals("")||cSubject.getText().equals("")||cMessage.getText().equals(""))
                    textArea.setText("One or more of the fields was not filled in.");
                else{
                      try {
                                String smtpServer="serverhere";
                                String to=cTo.getText();
                                String from=cFrom.getText();
                                String subject=cSubject.getText();
                                String body=cMessage.getText();
                                send(smtpServer, to, from, subject, body);
                                textArea.setText("");
                                description = "Mail Sent.";
                                JOptionPane.showMessageDialog(null, "Message Sent.");
            catch (Exception ex)
                System.out.println("Usage: java com.lotontech.mail.SimpleSender"
                +" smtpServer toAddress fromAddress subjectText bodyText");
                    //CLOSE THE FRAME2 WINDOW IIIIIIIIFFFFFFF SENDING IS SUCCESSFUL!!
                }//end of else during send
           }//end of if of submit
            displayResult(description);
        //============================
        protected void displayResult(String actionDescription) {
            textArea.append(actionDescription + newline);
        //=============================
        public void coolWindow() {
            JFrame frame = new JFrame("About");
            JTextArea filecontents = new JTextArea();
            filecontents.setText("Use the tool bar to compose\n compose new emails, in which you can\n send to anyone on the\n srvhs email server. \n Fill in all the blanks before pressing send. If you dont\n you will receive an error! \n For more information about this program click on the\n information button.");
            frame.getContentPane().add(filecontents, BorderLayout.CENTER);
            frame.pack();
            frame.setResizable(false);
            frame.setSize(300,200);
            frame.setVisible(true);
         //===============================
        public void composeWindow() {
            frame2.getContentPane().setLayout(new GridBagLayout());
            frame2.setResizable(false);
            frame2.setSize(600,500);
            frame2.setVisible(true);
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5, 10, 5, 10);
            cMessage.setLineWrap(true);
            subbutton = makeNavigationButton("toolbarButtonGraphics/general/SendMail24.gif", submit,"submit","submit");
            addRow(gbc, lFrom, cFrom);
            addRow(gbc, lTo, cTo);
            addRow(gbc, lSubject, cSubject);
            addRow(gbc, lMessage, cMessage);
            addRow(gbc, lSubmit, subbutton);
        //===============================
        private void addRow(GridBagConstraints gbc, Component left, Component right) {
            gbc.gridx = GridBagConstraints.RELATIVE;
            gbc.gridy = GridBagConstraints.RELATIVE;
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            gbc.anchor = GridBagConstraints.EAST;
            frame2.getContentPane().add(left, gbc);
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.anchor = GridBagConstraints.WEST;
            frame2.getContentPane().add(right, gbc);
            frame2.pack();
       //=======================
        public static void send(String smtpServer, String to, String from, String subject, String body) {
        try {
          Properties props = System.getProperties();
          props.put("mail.smtp.host", smtpServer);
          Session session = Session.getDefaultInstance(props, null);
          // -- Create a new message --
          Message msg = new MimeMessage(session);
          // -- Set the FROM and TO fields --
          msg.setFrom(new InternetAddress(from));
          msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
          // -- We could include CC recipients too --
          // if (cc != null)
          // msg.setRecipients(Message.RecipientType.CC
          // ,InternetAddress.parse(cc, false));
          // -- Set the subject and body text --
          msg.setSubject(subject);
          msg.setText(body);
          // -- Set some other header information --
          msg.setHeader("X-Mailer", "LOTONtechEmail");
          msg.setSentDate(new Date());
          // -- Send the message --
          Transport.send(msg);
          System.out.println("Message sent OK.");
        catch (Exception ex)
          ex.printStackTrace();
        public static void main(String[] args) {
            JFrame frame = new JFrame("EmailProg");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            EmailProg newContentPane = new EmailProg();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
    }

  • How to send email using pl/sql containing the result set as the msg body

    Hi.. im using Pl/SQL code to send emails to the users from a dataset that is obtained in a databse table. i have used utl_smtp commands to establish the connection with the smtp mail server. im stuck at the logic when i have to include the message body which is actually the result set of a table.. For instance
    IF (p_message = 0) THEN
    UTL_SMTP.write_data(l_mail_conn, 'There is no mismatch between the codes' || UTL_TCP.crlf);
    ELSE
    UTL_SMTP.write_data(l_mail_conn, 'The missing codes are ' || UTL_TCP.crlf);
    for s in (select * from temp)
    loop
    UTL_SMTP.write_data(l_mail_conn, ' ' ||s || UTL_TCP.crlf);
    end loop;
    END IF;
    UTL_SMTP.close_data(l_mail_conn);
    UTL_SMTP.quit(l_mail_conn);
    END;
    ***p_message is a prameter passed to this procedure..
    Can i obtain the result in the form i have it in my table. which has three columns. I want to display the three columns as it is with teh records. ?

    this is not related about this forum but you can use below,
    CREATE OR REPLACE PROCEDURE SEND_MAIL (subject varchar2,mail_from varchar2, mail_to varchar2,mail_msg varchar2)
    IS
    mail_host varchar2(30):='XXXXX';
    mail_conn utl_smtp.connection;
    tz_offset number:=0;
    str varchar2(32000);
    BEGIN
    begin
    select to_number(replace(dbtimezone,':00'))/24 into tz_offset from dual;
    exception
    when others then
    null;
    end;
    mail_conn:=utl_smtp.open_connection(mail_host, 25);
    utl_smtp.helo(mail_conn,mail_host);
    utl_smtp.mail(mail_conn,'[email protected]');
    utl_smtp.rcpt(mail_conn,mail_to);
    utl_smtp.open_data(mail_conn);
    utl_smtp.write_data(mail_conn,'Date: '||to_char(sysdate-tz_offset,'dd mon yy hh24:mi:ss')||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,'From: '|| mail_from ||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,'To: "'|| mail_to ||'" <'||mail_to||'>'||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,'Subject: '||subject||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,replace_turkish_chars(mail_msg)||utl_tcp.crlf);
    utl_smtp.write_data(mail_conn,utl_tcp.crlf);
    utl_smtp.close_data(mail_conn);
    utl_smtp.quit(mail_conn);
    END;
    Edited by: odilibrary.com on Jun 12, 2012 5:26 PM

  • How to send email using SPUtility.SendEmail method

    hi all,
             I am using SPUtility.SendEmail method to send email to list of users. but i am unable to send it. Code is not throwing any kind of error. Can anyone guide me steps to send email programmatically .
    Regards,
    Milan C.

    Hello Milan, 
    Humm, 
    Problably code is correct, need to speak with System administrator of mail server/exchange to know what rules exist on server mail.
    Verify if server mail validate IP from server to allow send mail. 
    Verify if exist some rule from server mail that validate sender with some domain "[email protected]"
    Verify if Email server have relay active to send Emails externaly
    Verify what type of authentication exist on you server Email, "Anonymous access or Login as password access", https? port number?
    This info is very important to have before you configure emails on sharepoint, to preview problems....  
    André Lage Microsoft SharePoint, CRM and Sybase Consultant
    Blog:http://aaclage.blogspot.com
    Codeplex:http://spupload.codeplex.com/http://simplecamlsearch.codeplex.com/

  • How to send emails using Automatic Work Items in Collections using XML Publ

    Hi,
    We are using XML Publisher to send correspondances in Advanced Collections.
    We want to send email correspondances using Automatic Strategy Work Items.
    Can anybody please help on how to send these?

    I believe you have to define your dunning template and assign that template to the strategy work item.
    Let me know if you are still not able to do it.
    Thanks,
    Anil

  • I am not able to send email using JAVA API to outer email

    If I am trying to send email from my company account to yahoo I am getting following errors:
    javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay
    for [email protected]
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at MailSend.main(MailSend.java:116)
    Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to rel
    ay for [email protected]
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
    ... 4 more
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for mkba
    [email protected]
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at MailSend.main(MailSend.java:116)
    Please let me know the reason for the same.

    Unable to relay - This happened because your Company network don't permit relay. Do talk to the network administrator and check with way safe you can send.
    I got the same problem, now im using through gmail.

  • How to send fax using java programming

    i need to send files in my hard disk through fax using java programming.
    i have found on the internet that it is possible to be implemented by using java.comm API and JTAPI. however, i don't know how...does anyone can tell me the details? also, as i know it will be a big project to send fax using such API. is that any other simple way to implement the fax function in java? thx a lot!

    To cse.mahbub:
    Are you aware that you replied to a 5 1/2 year old question?
    Please don't do that. Reply only to current questions.

Maybe you are looking for

  • I am a newer about LabVIEW.How can I realize a remote control in a Web brower.

    "To transform your application into a remote laboratory, make sure the VI that you want to publish is loaded into LabVIEW memory. Next, select the Web Publishing Tool option from the Tools menu. This window is the main window for interactively creati

  • Cannot preview attachments using Office Web App Server 2013 ( Preview )

    Got a lab environment to test Office Web App Server integration with Exchange 2013 i have followed the instructions given here http://technet.microsoft.com/en-US/jj219455 http://technet.microsoft.com/library/2591b1be-92c4-4192-9f5e-e4e6b319170a After

  • Error while doing PGR (post goods issue for sales order return)

    Hello Gurus, I'm trying to do PGR for a sales order return. But system shows the following message: "Shortfall below the specified stock level or quantity amounting to 100 UN". (Message number : M7021) I've made some searches in SD forum but I didn't

  • Can anyone put some light on this issue.

    When transferring PO idocs from R/3 to the middleware, some idocs doesn't reach the destination due to one buyers address segment not getting populated. Since this segment contains the address where it needs to to sent is missing, the idocs does not

  • Custom TOC WITHIN the Project?

    One glaring weakness (in my opinion) of Captivate is the inability to truly customize the TOC. What is included is flat-out ugly, and the customization options are quite limited. So it hit me today to try this: Use an Advanced Action, along with a si