Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在尝试发送电子邮件,收到的错误信息为“0”;这将导入java.mail“;无法解决_Java - Fatal编程技术网

正在尝试发送电子邮件,收到的错误信息为“0”;这将导入java.mail“;无法解决

正在尝试发送电子邮件,收到的错误信息为“0”;这将导入java.mail“;无法解决,java,Java,我正在尝试编写一个使用EclipseIDE发送邮件的简单程序,但我不能为邮件导入库。 在线上说 导入javax.mail.* 我听到一个错误说 "this import java.mail" cannot be resolved" 代码来自 JavaMail不随JavaSE提供。您可以从Oracle下载它。“this import java.mail”。它没有这么说。再看看。 import java.util.*; import javax.mail.*; import javax.mail

我正在尝试编写一个使用EclipseIDE发送邮件的简单程序,但我不能为邮件导入库。 在线上说 导入javax.mail.*

我听到一个错误说

"this import java.mail" cannot be resolved"
代码来自


JavaMail不随JavaSE提供。您可以从Oracle下载它。

“this import java.mail”。它没有这么说。再看看。
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
   public static void main(String [] args)
   {    
      // Recipient's email ID needs to be mentioned.
      String to = "abcd@gmail.com";

      // Sender's email ID needs to be mentioned
      String from = "web@gmail.com";

      // Assuming you are sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server
      properties.setProperty("mail.smtp.host", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Now set the actual message
         message.setText("This is actual message");

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }