我正在创建一个简单的java邮件程序,该程序工作正常,最后一个系统打印也工作。但问题是我没有在outlook中收到邮件。这里我使用的是公司outlook。请有人帮助我。 我在这里附上我的代码
enter code here
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SimpleSendEmail
{
public static void main(String[] args)
{
String host = "compny host";
String from = "mail id";
String to = "usr@some.com";
String subject = "birthday mail";
String messageText = "I am sending a message using the"
+ " simple.\n" + "happy birthday.";
boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("compny host", host);
props.put("mail.smtp.port", "25");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(props, null);
// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// will.
session.setDebug(sessionDebug);
try
{
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = { new InternetAddress(to) };
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
Transport.send(msg);
System.out.println("Sent message successfully....");
}
catch (MessagingException mex)
{
mex.printStackTrace();
}
}
}
output
Sent message successfully....
最佳答案
“公司主机”似乎不是正确的主机。查看本教程 http://www.tutorialspoint.com/java/java_sending_email.htm这里还有一些用 Java 发送电子邮件的示例 Send email using java
关于java - 如何使用Javamail发送简单的Email?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37721540/