我開發訪問公司的網絡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