Skip to main content

problem with javax.mail

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
lvvravikumar
Offline
Joined: 2011-11-30

hi everybody,

I am trying to devolop an application which'll send an E-Mail using Java. In that process i'm using javax.mail package. It'll throws an error "javax.mail" can not be resolved. and I've included javax-mail-1.3.jar External Jar, still i'm getting this problem. Can anybody help me in this......... :)

Thanks in Advance.

RaviKumar.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
khushifairy
Offline
Joined: 2011-12-08

Try to get "mail.jar" from internet and add it to your libraries.

then use this code: this requires a Gmail id. as gmail's server would be used here.

______________________________________________________________

package com.schedule.email;

import java.util.*;
import javax.mail.*
import javax.mail.internet.*;
import javax.activation.*;

public class Email {

protected static Session session;

/** The JavaMail message object */
protected static Message mesg;
private String message="testing file attachment";

public synchronized boolean doSend(){
try {
String subject="SMS Queue Hourly Notification";
String emailaddress="RECEIVERS EMAIL ADDRESS";

// Create the Session object
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.google.com");
session = Session.getDefaultInstance(props, null);
session.setDebug(true);
// create a message
mesg = new MimeMessage(session);
mesg.setFrom(new InternetAddress("SENDERS GMAIL ID"));
// TO Address
mesg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(emailaddress));

// The Subject
mesg.setSubject(subject);
// Now the message body.
Multipart mp = new MimeMultipart();
BodyPart pixPart = new MimeBodyPart();
pixPart.setContent(message, "text/html");
// Collect the Parts into the MultiPart
mp.addBodyPart(pixPart);
mesg.setContent(mp);
// Finally, send the message!
System.out.println("Senind E-mail to ::" +emailaddress);
System.out.println("Senind E-mail from :: " +"SENDERS GMAIL ID HERE");
Transport.send(mesg);
return true;

} catch (Exception ex) {
ex.printStackTrace();
return false;
}

} //EOM

public static void main(String[] args) throws Exception {
Email obj=new Email();
obj.doSend();
System.out.println("E-mail Sent...");

}
}

______________________________________________________________________________________

GOOD LUCK.

Valentine gifts Pakistan