how create package of this java code

how create package of this java code

Hi,i have email code in java which is working fine with out making package but when i want to make package of this code its stop working.Its showing exception while I execute it.I have to use this code in jsp to send mail. please help , my code is....

package javap;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;



public class sendmail
{

  private static final String SMTP_HOST_NAME = "smtp.gmail.com";
  private static final String SMTP_AUTH_USER = "abc";
  private static final String SMTP_AUTH_PWD  = "xyz";

  private static final String emailMsgTxt      = "this is test mail";
  private static final String emailSubjectTxt  = " Subject";
  private static final String emailFromAddress = "abc";

  // Add List of Email address to who email needs to be sent to
  private static final String[] emailList = {"xyz.com"};

  public static void main(String args[]) throws Exception
  {
    sendmail smtpMailSender = new sendmail();
    smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
    System.out.println("Sucessfully Sent mail to All Users");
  }

  public void postMail( String recipients[ ], String subject,
                            String message , String from) throws MessagingException
  {
    boolean debug = false;


     Properties props = new Properties();
     props.put("mail.smtp.host", SMTP_HOST_NAME);
     props.put("mail.smtp.auth", "true");

    Authenticator auth = new SMTPAuthenticator();
    Session session = Session.getDefaultInstance(props, auth);

    session.setDebug(debug);


    Message msg = new MimeMessage(session);


    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);

    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++)
    {
        addressTo[i] = new InternetAddress(recipients[i]);
    }
    msg.setRecipients(Message.RecipientType.TO, addressTo);



    msg.setSubject(subject);
    msg.setContent(message, "text/plain");
    Transport.send(msg);
 }


private class SMTPAuthenticator extends javax.mail.Authenticator
{

    public PasswordAuthentication getPasswordAuthentication()
    {
        String username = SMTP_AUTH_USER;
        String password = SMTP_AUTH_PWD;
        return new PasswordAuthentication(username, password);
    }
}

}
View Answers

Ads









Related Tutorials/Questions & Answers:
how create package of this java code
how create package of this java code  Hi,i have email code in java which is working fine with out making package but when i want to make package... this code in jsp to send mail. please help , my code is.... package javap
how create package of this java code
how create package of this java code  Hi,i have email code in java which is working fine with out making package but when i want to make package... this code in jsp to send mail. please help , my code is.... package javap
Advertisements
How to Create CurveDraw In Java
How to Create CurveDraw In Java       Introduction In this section, you will learn how to create CurveDraw in java.awt package. This class,supported by the java.awt.geom package
How to Create Text Area In Java
How to Create Text Area In Java       In this section, you will learn how to create Text Area in Java... and it's constructor of java.swing package. In the code of the example, constructor
How to Create Circle In Java
How to Create Circle In Java     ..., you will learn how to create Circle Diagram. The java circle is the most fundamental abstractions in a Java 2D in the supported  java.awt.shape package
how to create notepad in java
how to create notepad in java  how to create notepad in java
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
How to create charts in Java?
How to create charts in Java?  Is there any example of creating charts and graphs in Java? thanks   Hi, check the tutorial: Chart & Graphs Tutorials in Java Thanks
How to Create Keyboard in JAVA
How to Create Keyboard in JAVA  please help me to create On-Screen Keyboard with java and please give me an another idia to make it ..............iam waiting for your help ,think u so much
how to create interfaces in java
how to create interfaces in java  HI, Here is my code public interface validateInfo { public void validate(String empcode, String password); } class updateInfo implements validateInfo { public void update() { //code
What is a Java package and how is it used?
What is a Java package and how is it used?   HI, What is a Java package and how is it used? thanks,   Hi, In Java, package is a group... functionality. For related to Java Package read this articles link: http
ModuleNotFoundError: No module named 'create-package'
named 'create-package' How to remove the ModuleNotFoundError: No module named 'create-package' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'create-package'  Hi, My
ModuleNotFoundError: No module named 'create-package'
named 'create-package' How to remove the ModuleNotFoundError: No module named 'create-package' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'create-package'  Hi, My
How to Create Button on Frame
How to Create Button on Frame       In this section, you will learn how to create Button on  frame the topic of Java AWT package. In the section, from the generated output
how to create reports in swing java?
how to create reports in swing java?  how to create reports in swing java
How to create and use Array in Java?
How to create and use Array in Java?  Hi, How to create and use Array in Java? Write program to construct and use the array. Thanks   Hi...]; Above example code initializes an array with a capacity of 10. After
How to create first program in Java?
How to create first program in Java?  Hi, I am new in Java programming. Tell me How to create first program in Java? Thanks   Hi, Read more at First Java Program. Thanks
How to create first Java Program?
How to create first Java Program?  Hi, I am beginner and I want to write first Java program. How I can setup my machine and write first Java program... and run first Java program: Create program in Note pad: Step 1: Open
java source code to create mail server using struts2
java source code to create mail server using struts2  java source code to create mail server using struts2
java code to create xml document from DOM object
java code to create xml document from DOM object  Hey! After knowing the way we can create DOM objects and add elements to it-> then displaying it on the console ;is there a way I can output the same in xml document
ModuleNotFoundError: No module named 'create-python-package'
: No module named 'create-python-package' How to remove the ModuleNotFoundError: No module named 'create-python-package' error? Thanks   Hi...ModuleNotFoundError: No module named 'create-python-package'  Hi
ModuleNotFoundError: No module named 'create-python-package'
: No module named 'create-python-package' How to remove the ModuleNotFoundError: No module named 'create-python-package' error? Thanks   Hi...ModuleNotFoundError: No module named 'create-python-package'  Hi
ModuleNotFoundError: No module named 'create-python-package'
: No module named 'create-python-package' How to remove the ModuleNotFoundError: No module named 'create-python-package' error? Thanks   Hi...ModuleNotFoundError: No module named 'create-python-package'  Hi
ModuleNotFoundError: No module named 'termux-create-package'
: No module named 'termux-create-package' How to remove the ModuleNotFoundError: No module named 'termux-create-package' error? Thanks   Hi...ModuleNotFoundError: No module named 'termux-create-package'  Hi
ModuleNotFoundError: No module named 'termux-create-package'
: No module named 'termux-create-package' How to remove the ModuleNotFoundError: No module named 'termux-create-package' error? Thanks   Hi...ModuleNotFoundError: No module named 'termux-create-package'  Hi
How to Create Student Registration Form with HTML Code?
How to Create Student Registration Form with HTML Code? At present... will learn to create a student registration form using html code in easy steps... html code for student registration form JavaScript validation has been used
How to delete file in Java code?
How to delete file in Java code?  Hi, From my Java program I have to delete a file. How to delete file in Java code? Thanks   Hi, Java... complete example code at How to delete file in Java?. Thanks   Hi, Also
How to convert this Java code into GUI?
How to convert this Java code into GUI?   import java.util.Scanner; public class StudentMarks { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks
How to create custom exception in Java?
How to create custom exception in Java? In this tutorial we are going to create our own exception class and you will learn the steps to create custom exception class. Custom exceptions are used by Java developers to create
How to create LineDraw In Java
How to create LineDraw In Java     ... will learn how to create Line Drawing. This program  implements a line Drawing component. A java program explains the stroke line i.e. how to make thick
how to create users in LDAP using java?
how to create users in LDAP using java?  how to create users in LDAP using java

Ads