1
ローカルメールサーバーからGmailにメールを送信する必要があります.MAMPはXAMPP.Iで設定しました。JavaMail APIを使用してメールを送信するJavaプログラムを作成しました。それはそれが送信されたことを示しています。しかし、私はGmailでメールを受信しませんでした。続きjspのXAMPPで水銀サーバーを使用してメールを送信する
は、コードがインターネット
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMailBySite {
public static void main(String[] args) {
String host="127.0.0.1";
final String user="[email protected]";//change accordingly
final String password="root";//change accordingly
String to="[email protected]";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,password);
}
});
//Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("javatpoint");
message.setText("This is simple program of sending email using JavaMail API");
//send the message
Transport.send(message);
System.out.println("message sent successfully...");
} catch (MessagingException e) {e.printStackTrace();}
}
}
からplsは私を修正して誰もがそれを得ています。
これが唯一のJavaコードである私は、後でJSP /サーブレット – SKJ