我建立在Java的電子郵件應用程序,到目前爲止,我嘗試使用這個,我正在上運行該代碼中沒有錯誤,但經過我編譯和運行代碼的問題是,淨豆IDE只是表明我的計劃正在運行,但是當我檢查郵箱時,沒有郵件收到。任何人都可以解釋爲什麼發生這種情況?爲什麼我的郵件沒有發送?
而且我打印的消息「發送成功」消息結尾,但不知何故沒有得到打印的消息,我也弄不清是什麼錯誤,任何幫助,將不勝感激,謝謝。如果你的代理/防火牆後面運行
public class Email
public static void main(String[] args) {
// TODO code application logic here
String[] to = {"[email protected]"};
String from = "[email protected]";
String host = "smtp.gmail.com";
String user_name = "[email protected]";
String password = "xyz";
try{
Properties properties = System.getProperties();
properties.setProperty("smtp.gmail.com", "imaps");
properties.put("smtp.starttls.enable", "true");
properties.put("mail.smtp.host",host);
properties.put("mail.smtp.user",user_name);
properties.put("mail.smtp.password", password);
properties.put("mail.smtp.port", "465");
properties.put("mail.smtp.auth", "true");
//properties.put
Session session = Session.getDefaultInstance(properties,null);
//Store store = session.getStore("imaps");
MimeMessage message = new MimeMessage(session);
// basically stores one or more addresses , whom the mail has to be sent
//InternetAddress[] send_to = { new InternetAddress(to) };
//InternetAddress[] send_from = { new InternetAddress(from) };
InternetAddress[] toAddress = new InternetAddress[to.length];
for(int i = 0; i < to.length ;i++)
{
toAddress[i] = new InternetAddress(to[i]);
}
for(int i = 0 ; i < toAddress.length ; i++){
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setFrom(new InternetAddress(from));
message.setSubject("Testing email");
message.setText("this is a test");
Transport transport = session.getTransport("smtp");
transport.connect(host, user_name, password);
transport.send(message);
transport.close();
System.out.println("Message successfully sent");
}catch(Exception e){
e.printStackTrace();
}
}
}
嘿我試過使用上面的代碼,但我得到以下錯誤。 http://dl.dropbox.com/u/53861781/Links/link.txt,我已經指定了用戶名,但爲什麼它仍然顯示我這個錯誤? – Sam