Jakarta mail 如何使用java发送电子邮件

Jakarta mail 如何使用java发送电子邮件,jakarta-mail,sendmail,Jakarta Mail,Sendmail,我知道有很多这样的问题,但它们对我不起作用 因此,如果有任何方法可以用java发送电子邮件 (yahoo、hotmail或gmail)对不起,伙计们,我的防病毒软件出了问题,我刚关掉它,它就工作了,这是代码。。。。别忘了关掉杀毒软件 import java.util.*; import javax.mail.*; import javax.mail.internet.*; public class SendFrom { public static void main(String [] arg

我知道有很多这样的问题,但它们对我不起作用 因此,如果有任何方法可以用java发送电子邮件
(yahoo、hotmail或gmail)

对不起,伙计们,我的防病毒软件出了问题,我刚关掉它,它就工作了,这是代码。。。。别忘了关掉杀毒软件

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

public class SendFrom
{
public static void main(String [] args)
{    
    // Sender's email ID needs to be mentioned

     String from = "YourEmail@gmail.com";//

     String pass ="YourPassword";
    // Recipient's email ID needs to be mentioned.
   String to = "DestinationEmail";
   String host = "smtp.gmail.com";


   // Get system properties
   Properties properties = System.getProperties();
   // Setup mail server
   //props.put("mail.smtp.ssl.trust", host);
   //properties.put("mail.smtp.ssl.enable", "true");
   properties.put("mail.smtp.starttls.enable", "true");
   properties.put("mail.smtp.host", host);
   properties.put("mail.smtp.user", from);
   properties.put("mail.smtp.password", pass);
   properties.put("mail.smtp.port", "587");
   properties.put("mail.smtp.auth", "true");
   properties.put("mail.debug", "true");

   // 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 transport = session.getTransport("smtp");
      transport.connect(host, from, pass);

      transport.sendMessage(message, message.getAllRecipients());
      transport.close();
      System.out.println("Sent message successfully....");
   }catch (MessagingException mex) {
      mex.printStackTrace();
   }
}
}

你能发布你的代码吗?什么不适合你?你试过什么?你是认真的问我们而不提供任何细节吗?谷歌它。。。了解别人是如何做到这一点的。。展示一些例子并解释为什么它们不起作用。。否则,我想是第12行的变量2