2017-02-04 2 views
1

Ich muss eine Mail an Gmail von lokalen Mail-Server Mercury in XAMPP.Ich habe es konfiguriert.Ich schrieb ein Java-Programm zum Senden einer E-Mail mit JavaMail-API. Wenn ich Führen Sie es aus, es zeigt, dass es gesendet wurde. Aber ich habe keine Mail in Google Mail erhalten.Senden einer E-Mail an Gmail mit Quecksilber-Server in XAMPP in JSP

Es folgt der Code wurde es aus dem Internet

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();} 
} 
} 

Jeder pls mich korrigieren.

+0

Dieses nur Java-Code ist werde ich es später Umwandlung in jsp/Servlet – SKJ

Antwort

1

Ihre smpt Server ändern Konfiguration auf diese und nehmen die gmail SMTP-Server von Google zu verwenden:

String host = "smtp.gmail.com"; 
final String user="[email protected]"; 
final String password="your gmail account password";//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); 
props.put("mail.smtp.starttls.enable", true); 
props.put("mail.smtp.port", 587); 
+0

Danke der Code funktioniert @FrAn gut ... und ich erhielt Post. – SKJ