Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaMail how create package of this java code

Have Programming Question? Ask it here!
 
 
 


vishal bharti
how create package of this java code
0 Answer(s)      3 years and 5 months ago
Posted in : JavaMail


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 SMTPHOSTNAME = "smtp.gmail.com"; private static final String SMTPAUTHUSER = "abc"; private static final String SMTPAUTHPWD = "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);
}

}

}


Advertisement
View Answers

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
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
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
Java zip package - Learn how to use java zip package.
Java zip package In this section we will learn about java.util.zip package of java library. We will also learn how to use the zip API to create and read... the archive files. The java zip package provides the API for reading and writing
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
Java package
Java package  What restrictions are placed on the location of a package statement within a source code file
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 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
Java package
Java package  Which package is always imported by default
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
Create Your Own Package
Create Your Own Package      ... with the keyword package at the top left of the source file, before the code...-qualified class name is the name of the java class that includes its package name
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 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
package in java
package in java  when i run a package it give a error exception in thread "main" java.lang.NoClassDefFoundError what i do
Package in Java - Java Beginners
Package in Java  Hi, What is a package? Tell me how to create package? Thanks   Hello, packeage is nothing but you can say that folder of related java files. ex, if you write a jaava class like
add new package java
add new package java  How to add new package in Java
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
Creating your own package in java
package at the top left of the source file, before the code that defines the real classes in the package. To know more about how to create own package and subpackage click on the following links Create Your Own Package Create
how to create executable - Java Beginners
how to create executable  How do i create a executable file from a java file thnks in adv...!  Hi Friend, Try the following code: import java.io.*; import java.util.jar.*; public class CreateExe { public
about package - Java Beginners
package. I am unable to understand as it is a rule to create the package in the root directory.In my system java is installed in c:\ibm\java142\bin how can i run...://www.roseindia.net/java/master-java/java-package.shtml Hope
Java package,Java Packages
convention defines how to create a unique package name, so that packages... Java Package       Introduction to Java Package A Java package is a mechanism for organizing a group
Code how to? - Java Beginners
Code how to?  how to access a separate form using a JButton ? Also how to let another Jbutton access an excel spreadsheet for viewing? Thanks
package - Java Beginners
Creating a package in Java  Create a package called My Package. In this, create a class call Marks that specifies the name of student, the marks in three subjects and the total of these marks. Displays the details of three
Code how to? - Java Beginners
Code how to?  how to access a separate form using a JButton ? Also how to let another Jbutton access an excel spreadsheet for viewing? Thanks  Hi Friend, We are providing you a code that will display a form
how to create exce sheet using java
how to create exce sheet using java  how to create excel sheet using java
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
how to create a header in jtable using java swing
how to create a header in jtable using java swing  how to create a header in jtable using java swing   d
Java nio package - Learn how to use java nio package.
package and how it is implemented in java programming...Java nio package. In this section we will learn about the java.nio package. We will also see how to use java.nio package classes
NIO Tutorials, Java nio tutorial, Java nio package tutorial
to Create a ByteBuffer using Byte Array in java.   How to transfer data... will discuss about the Sun java nio package. This nio tutorials will help you learn nio package with examples. We are providing many examples on the Java nio
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
Package categories in Java
Package categories in Java       Java supports two types of packages as shown below....  java.nio This package handles New I/O framework for Java
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt....(Exception e){} } else{ System.exit(0); } } }); tp.addTab("Create Account",panel
java awt package tutorial
Java AWT Package In Java, Abstract Window Toolkit(AWT) is a platform independent widget toolkit for windowing, graphics, and user-interface. As the Java... are added to the Container object to create a Graphical User Interface (GUI
Java AWT Package Example
This program shows you how to create a frame in java AWT package... will learn how to create Button on  frame the topic of Java AWT package... In this section, you will learn how to create arcs diagram in java awt package. The Java
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt....(Exception e){} } else{ System.exit(0); } } }); tp.addTab("Create Account",panel
how to create this diamond structure with java. - Java Beginners
how to create this diamond structure with java.   * *** ***** * *** *** * ***** * *** *** * ***** * *** *** * ***** *** *  ..., Try the following code: class Stars{ public static void main(String
how to create month wise serial number in java?
how to create month wise serial number in java?  Ex: For 1)January-serial number is 1/001,1/002,1/003 etc
Create Subpackages (i.e. A Package inside another package)
Create Subpackages (i.e. A Package inside another package)       We can also put a package... "subpackage". The naming convention defines how to create a unique
How to Create Car Rental Application in Java ?
How to Create Car Rental Application in Java ?  Hi, How to Create a Car Renal Application using Java to Check the Car renting, booking... the car rental apps in Java
java how to create visual swing editor
java how to create visual swing editor   How do I create a visual swing designer in java ?Meaning that I can "draw" a button,a JTextArea from within my designer program . I just need some basics . I've got no idea how to start
how to create unit matrix in java of arbritary dimensions
how to create unit matrix in java of arbritary dimensions  i want to create the unit matrix of arbritary dimensions say (n*m).i m a new beginner to java.someone having the program for that? help would be appreciable
java.util package - Java Beginners
java.util package  Design a Date class similar to the one provided in the java.util package.? Thanks in ADVANCE....  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/java/core
How to create new arraylist using Java
someone provides online example how to create new arraylist in java programming. thnaks,   Hi, In java programming language you can create new...How to create new arraylist using Java  hi, I want to develop
how to run java program that has several classes under package from usb drive?
how to run java program that has several classes under package from usb drive?  I have an assignment where I have to submit my code in flash drive. I... command line and it works. I copied all java files and class files to flash drive
 

 

 

DMCA.com