我正在寫一些應用程序,我需要發送郵件。我的應用程序是在JAVA中,所以我可能會使用javamail。但我不知道如何使用它,以及如何從我的本地電腦配置郵件服務器,以便我可以測試郵件是否可以發送。請建議。我正嘗試在java中編寫簡單的郵件程序。我應該使用什麼。我如何配置我的本地機器發送郵件?
1
A
回答
3
您還可以使用GMAIL smtp發送郵件。
下面是一個示例代碼段
String host = "smtp.gmail.com";
String from = "username";
String pass = "password";
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true"); // added this line
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
String[] to = {"[email protected]"}; // added this line
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
// To get the array of addresses
for(int i=0; i < to.length; i++) { // changed from a while loop
toAddress[i] = new InternetAddress(to[i]);
}
System.out.println(Message.RecipientType.TO);
for(int i=0; i < toAddress.length; i++) { // changed from a while loop
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setSubject("sending in a group");
message.setText("Welcome to JavaMail");
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
+0
對谷歌的任何依賴。我可以發送郵件到任何電子郵件地址嗎? – 2010-10-27 16:30:06
+0
@sushil bharwani,是的,你可以將它發送到任何有效的郵件地址,谷歌的服務器將得到使用。這是唯一的依賴 – 2010-10-27 16:31:26
+0
可以使用我的谷歌smtp服務器的生產級別的代碼。就像我用它發送20,000個員工的郵件一樣。對不起,如果我聽起來很愚蠢。 – 2010-10-27 16:36:17
相關問題
- 1. 用java發送郵件(我正在使用java郵件API)
- 2. 爲什麼我的郵件不發送,但我配置smtp?
- 3. 如何使用codeigniter郵件程序在我的郵件帳戶中發送main?
- 4. 垃圾郵件正在使用我的域名發送,我該怎麼辦?
- 5. 我想在JAVA中爲僅郵件發送郵件創建一個簡單的JAX_RS Web應用程序?
- 6. 在我的Java應用程序中實現正確的郵件發送
- 7. 我如何確保我的郵件($ to,$ subject,$ msg);發送郵件
- 8. 我應該用什麼庫來發送電子郵件ruby
- 9. 我該如何配置php swiftmailer發送電子郵件
- 10. 如何在我的Rails 5郵件程序中配置「發件人」地址?
- 11. 如何從我的iOS應用程序發送郵件 - SWIFT
- 12. 如何從我的應用程序發送電子郵件?
- 13. 我的Parse.com應用程序如何發送電子郵件?
- 14. 如何從我的Facebook應用程序發送電子郵件
- 15. 如何告訴我的應用程序發送電子郵件?
- 16. 如何從我的C#應用程序發送電子郵件?
- 17. 如何從我的應用程序發送郵件
- 18. 如何在我的Symfony2應用程序中調試電子郵件發送?
- 19. 我如何發送電子郵件從本地主機到我的gmail
- 20. 我想在javaFx應用程序中發送郵件的代碼
- 21. 在我的應用程序中發送郵件laravel 4.2
- 22. 爲什麼我的郵件正文並未在drupal_mail()中發送?
- 23. 我的郵件作爲垃圾郵件發送,我使用php郵件()
- 24. 我該如何將facebookmail的電子郵件發送給我的應用用戶?
- 25. 我想在我的應用程序中發送來自iPhone的郵件
- 26. 我將如何通過我的vb.net應用程序發送電子郵件?
- 27. 如何使用電子郵件應用程序從我的應用程序發送電子郵件?
- 28. 我怎麼能從web應用程序發送郵件
- 29. 當我嘗試發送電子郵件時,應用程序崩潰
- 30. 爲什麼我無法從我的servlet發送電子郵件?
我認識到GMAIL SMTP支付。有人可以提出一些免費的建議。 – 2010-10-27 17:23:45