以下は、Javaを使用して電子メールを送信するために書いた簡単なテストクラスです。私はローカルホストからメッセージを送信しようとしています。しかし、私は次のようなエラーメッセージが出ます:Javaでメールを送信する
javax.mail.MessagingException: Unknown SMTP host: http://localhost:8080/;
nested exception is:
java.net.UnknownHostException: http://localhost:8080/
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1280)
を私は単純に「localhost」をに値をホストするために変更するが、私は同じ問題を取得します。修正に関するアイデアはありますか?実際のサーバーは機能しますか?
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MyEmail {
public static void main(String... args) {
String to = "[email protected]";
String from = "[email protected]";
String host = "http://localhost:8080/";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host",host);
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("This is a subject");
message.setText("The text is what it is the text");
Transport.send(message);
System.out.println("Successful");
}catch(MessagingException mx){
mx.printStackTrace();
}
}
}
あなたはどこでメールデーモンを実行していますか? –