导入javax.mail无法解析 [英] The import javax.mail cannot be resolved

查看:1269
本文介绍了导入javax.mail无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 = "testing@gmail.com";
    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);
    }
};

我正在开发一个应用程序,应用程序会自动向用户发送一封电子邮件通知用户当前的手机手机被盗或丢失后的状态。但我在导入javax.mail时遇到问题导入javax.mail无法解析。我该怎么办?谢谢...

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...

推荐答案

尝试添加此 javax.mail.jar
。您可以下载它这里
,希望这会有所帮助。
类似的问题此处

这篇关于导入javax.mail无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆