Java Email
i am writting a program to send emails using gmail smtp server. I had the following error:
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
Could anyone help me correct this? here is the code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package JavaMail;
import MISC.Repository;
import java.util.Properties;
/*
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
*/
import javax.mail.*;
import javax.mail.internet.*;
/**
*
* @author Aileen
*/
public class SendMail {
String username;
String password;
String mailServer;
Session session;
Message message;
public SendMail (String mServ, String un, String pw) {
username = un;
password = pw;
mailServer = mServ;
Properties props = new Properties ();
props.put("mail.smtp.host", mailServer);
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,password);
}
});
}
public void setFields (String sub, String msg, String hName, String hVal) {
try {
message = new MimeMessage(session);
message.setHeader(hName, hVal);
message.setSubject(sub);
message.setText(msg);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void mailer (String from, String to) {
try {
message.setFrom(new InternetAddress (from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
Transport.send(message);
Repository.showMessage("Message Successfully Sent to "+to, "SUCCESS", 'P');
}catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public static void main (String args[]) {
SendMail sm = new SendMail ("smtp.gmail.com", "elimence", "awonkyarok");
sm.setFields("HELLO", "DOES IT WORK", "HEADER", "HEADER VALUE");
sm.mailer("Sector 7", "[email protected]");
}
}
View Answers
Related Tutorials/Questions & Answers:
Java EmailJava Email I am making one
java email applications using jsp-servlets. can you tell me that how can i recieve and send
email dynamically in my application in UI...
thanx.
Hi,ADS_TO_REPLACE_1
Please read at
Email Java EmailJava Email i am writting a program to send emails using gmail smtp server. I had the following error:
java.lang.ClassFormatError: Absent Code...)
Exception in thread "main"
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds
Advertisements
email extractor - Java Beginnersemail extractor how to extract only
email address from a lines of text file(.txt or .doc) and print in another file?
will u send me answer in c...; Sorry!
I am a
java developer.It's been long time that i left 'C
email email hi
I am using 1and1 server. Using this server i am sending a mail using
java program .
But it is running some problem occur
" Cannot send
email. javax.mail.SendFailedException: Invalid Addresses;ADS_TO_REPLACE_1
email extractor - Java Beginnersemail extractor how to extract only
email address from a lines... queries.
/**
* Program to scan
email address from a file and write into an other...";
String line = null;
String
email="";
try {
File file = new File
emailemail how do i code for making clicking a send button sends a
email java code to send an emailjava code to send an email i developed one
java code that has to send a mail but i am getting an runtime exception calledjavax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested
javascript-email validation - Java Beginnersjavascript-
email validation give the detail explanation for this code:
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr... about
email validation at:
http://www.roseindia.net/jsp/valid-
email-jsp.shtml
To send pdf file to email in java To send pdf file to
email in
java Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
at javax.mail.Session.initLogger(Session.java:283)
at javax.mail.Session.
Email Validation code - Java Interview QuestionsEmail Validation code Can anybody tell me how to write
email validation code using
java Hi Friend,
Please visit the following link:
http://www.roseindia.net/tutorial/
java/core/regularExpressions.html
Thanks
Read Email using Java Mail API - James Read
Email using
Java Mail API - James https://www.roseindia.net/javamail/send-mail.shtml
From this sample, i understand that we need to pass user credentials for reading the
email content.
Is there any option to read all
Read Email using Java Mail API - James Read
Email using
Java Mail API - James https://www.roseindia.net/javamail/send-mail.shtml
From this sample, i understand that we need to pass user credentials for reading the
email content.
Is there any option to read all
Read Email using Java Mail API - James Read
Email using
Java Mail API - James https://www.roseindia.net/javamail/send-mail.shtml
From this sample, i understand that we need to pass user credentials for reading the
email content.
Is there any option to read all
Read Email using Java Mail API - James Read
Email using
Java Mail API - James https://www.roseindia.net/javamail/send-mail.shtml
From this sample, i understand that we need to pass user credentials for reading the
email content.
Is there any option to read all
sending email using smtp in javasending
email using smtp in java Hi all,
I am trying to send and
email to through my company mail server. Following is my code
package com.tbss;
import javax.mail.*;
import javax.mail.internet.*;
import
how to send sms on mobile and email using java codehow to send sms on mobile and
email using
java code hi....
I am developing a project where I need to send a confirmation/updation msg on clients mobile and also an
email on their particular
email id....plz help me to find
Change EmailChange Email Hi, I need to change my Rose India register
email address for receive
email, How did it possible
email validationemail validation during
email validation.... after domain name which it means if example
[email protected] .... this address allowed by any validation program .... but i want to show invalid
email address because domain name com
email validationemail validation during
email validation.... after domain name which it means if example
[email protected] .... this address allowed by any validation program .... but i want to show invalid
email address because domain name com
JSP EmailJSP Email Hi,
How to send
email using JSP?
Thanks
Hi,
Check this tutorial: Send
Email to selected dropdown user
Thanks
Email sendingEmail sending Hi sir,
Am doing a project, in that i need to send
email to multiple recipients at a same time using jsp so send me the code as soon as possible.
Regards,
Santhosh