我开发访问公司的网络Java邮件不会在公司的网络中工作
一切工作除了Java邮件库
当我拔下它仅罚款的桌面应用程序设备从公司的网络连接到一个普通的无线网络,但是一旦我连接到公司的网络,它就不会发送任何电子邮件。
我该如何解决问题?
我用于java邮件的电子邮件是Gmail帐户。
以下是邮件类的源代码:
public class Email {
public void sendEmail(String from, String recipent, String title, String name, String textmsg, String emp_id) throws IOException {
final String user = "******@gmail.com";
final String password = "*****";
String host = "mail.javatpoint.com";
String to = recipent;
Properties properties = System.getProperties();
properties.put("mail.smtp.starttls.enable", "true");
properties.setProperty("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user, "IT Communication Database"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(title);
message.setContent("Below are the assets that were found for the following user: " + emp_id + "\n" + textmsg, "text/html");
Transport.send(message);
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
public void sendEmail(String from, String recipent, String title, String name, String textmsg, String search_word) throws IOException {
final String user = "*****@gmail.com";
final String password = "*****";
String host = "mail.javatpoint.com";
String to = recipent;
Properties properties = System.getProperties();
properties.put("mail.smtp.starttls.enable", "true");
properties.setProperty("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user, "IT Communication Database"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(title);
Transport.send(message);
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
}
那么,您正在使用无法从您的公司网络访问的smtp服务器(smtp.gmail.com)。要么让您的公司使其可访问,要么使用另一台可从网络访问的smtp服务器。 – 2014-09-27 17:33:05
哦,我会检查他们!感谢您的快速回复 – Wesamz 2014-09-27 17:40:11
请问除smtp之外是否还有其他选项可能会起作用? @JB Nizet – Wesamz 2014-09-27 17:43:15