Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The import javax.mail cannot be resolved [duplicate]

Tags:

java

android

import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;    

private void sendMail() throws MessagingException{

    String host = "smtp.gmail.com";
    String password = "abcde12345";
    String from = "[email protected]";
    String toAddress = email;
    String filename = Environment.getExternalStorageDirectory() + "/jam.jpg";

    Properties properties = System.getProperties();
    properties.put("mail.smtp.host", host);
    properties.put("mail.smtps.auth", true);
    properties.put("mail.smtp.starttls.enable", true);
    Session session = Session.getInstance(properties, null);

    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipients(Message.RecipientType.TO, toAddress);
    message.setSubject("Anti-Theft Attachment");

    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(smsMessageString);

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    message.setContent(multipart);

    try{
        Transport transport = session.getTransport("smtps");
        transport.connect(host, from, password);
        transport.sendMessage(message, message.getAllRecipients());
        System.out.println("Mail Sent Successfully");
        transport.close();
    } catch (SendFailedException sfe){
        System.out.println(sfe);
    }
};

I am developing an application which the application will automatically send out an email to user informing user the current phone status once the phone is stolen or lost. But I faced problem in importing javax.mail "The import javax.mail cannot be resolved". What should I do? Thanks...

like image 232
Android_Rookie Avatar asked Oct 09 '12 08:10

Android_Rookie


People also ask

How do I resolve javax mail Messagingexception?

Try the following: Download the java mail jars from: http://www.oracle.com/technetwork/java/javamail/index-138643.html. Add the jars to your WEB-INF/lib folder. Add the jars to Java Build Path > Libraries.

How do I get the javax email?

You will need the JavaBeans Activation Framework (JAF) extension that provides the javax. activation package only when you're not using Java SE 6 or newer. You can download latest version of JavaMail (Version 1.5. 0) from Java's standard website.

Is javax mail part of JDK?

This book covers Version 1.5 of the JavaMail API. The JavaMail API is a standard extension to Java, not part of the core JDK or JRE class library, even in Java 8.


1 Answers

Try add this javax.mail.jar .You can download it here ,hope this will help. There is a similar question here.

like image 93
xKommando Avatar answered Sep 20 '22 16:09

xKommando