Ich habe viele andere Beiträge hier mit Benutzern mit ähnlichen Problemen durchsucht, aber ich kann es einfach nicht funktionieren.Senden Sie eine E-Mail an den E-Mail-Server meiner Arbeit mit JavaMail
package testingstuff;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.Message.RecipientType;
import javax.mail.internet.*;
import javax.activation.*;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
final String user = "my work ID";
final String pw = "my work Password";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "server I got from our outlook app");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, pw);
}
});
session.setDebug(true);
try {
Message msg = new MimeMessage(session);
String from = "[email protected]";
String to = "[email protected]";
msg.setFrom(new InternetAddress(from));
msg.setRecipient(RecipientType.TO, new InternetAddress(to));
msg.setSubject("TEST");
msg.setText("TESTING");
//Transport trans = session.getTransport("smtp");
//trans.connect("smtp-mail.outlook.com", 25, user, pw);
Transport.send(msg);
}
catch (Exception e) {
System.out.println(e);
}
System.out.println("done");
}
}
ich verwende Java 1.8, berichtet Java Mail, dass es Version 1.4.7
Hier wird die Ausgabe von der Sitzung debug:
Hello World
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "[my work email server]", port 587, isSSL false
javax.mail.MessagingException: Could not connect to SMTP host: [my work email server], port: 587;
verschachtelte Ausnahme ist:
java.net.ConnectException: Connection timed out: connect
erledigt
Der E-Mail-Server, den ich verwende, stammt aus der Outlook-App. Ich ging zu Kontoeinstellungen, wählte mein Konto und ausgewählte Änderung. Dies öffnet ein Fenster mit der Konfiguration für die E-Mail und es enthält die Serveradresse.
Ich habe versucht, das vorher und es hat auch nicht funktioniert. Ich schickte es von einem Arbeitsnetzwerk, so dass es blockiert wurde. Ich schlage vor, eine E-Mail an eine private Gmail oder etwas und sehen, ob das funktioniert –
Vielleicht kann die Portnummer ein Problem verursachen. Versuchen Sie zum Beispiel "80". – pilkington