我在这里和其他地方搜索了几个相关的帖子,但没有一个解决了我的问题.我有一个程序使用"javamail API"向一组人发送电子邮件.它工作得很好.今天我再次需要,但我无法发送任何电子邮件...我的sendEmail方法如下:
public void sendEmail(String userName, String password, String toAddress,
String subject, String message, String[] attachFiles)
throws AddressException, MessagingException {
// sets SMTP properties
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.user", userName);
properties.put("mail.password", password);
// creates a new session with an authenticator
Authenticator auth = new SMTPAuthenticator(userName, password);
Session session = Session.getInstance(properties, auth);
// creates a new e-mail message
MimeMessage msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(userName, "My name"));
} catch (UnsupportedEncodingException …Run Code Online (Sandbox Code Playgroud)