Java 在jsp的XAMPP中使用mercury服务器向gmail发送邮件
我需要在XAMPP中从本地邮件服务器Mercury向gmail发送邮件。我配置了它。我编写了一个java程序,使用JavaMail API发送邮件。当我运行它时,它显示它已发送。但是,我没有在gmail中收到任何邮件 下面是从互联网上获得的代码Java 在jsp的XAMPP中使用mercury服务器向gmail发送邮件,java,jsp,email,Java,Jsp,Email,我需要在XAMPP中从本地邮件服务器Mercury向gmail发送邮件。我配置了它。我编写了一个java程序,使用JavaMail API发送邮件。当我运行它时,它显示它已发送。但是,我没有在gmail中收到任何邮件 下面是从互联网上获得的代码 import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class SendMailBySite { public s
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="root@localhost.com";//change accordingly
final String password="root";//change accordingly
String to="kishorejohnsan.s@gmail.com";//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();}
}
}
任何人请纠正我。将您的smpt服务器配置更改为此,并使用谷歌的gmail smtp服务器:
String host = "smtp.gmail.com";
final String user="kishorejohnsan.s@gmail.com";
final String password="your gmail account password";//change accordingly
String to = "kishorejohnsan.s@gmail.com";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.port", 587);
这是唯一的java代码,稍后我会将其转换为jsp/servletThank you@FrAn代码运行良好。。。我收到了邮件。