[英]How to send email from a java web app
我有一個坐在Tomcat / Apache上的java Web應用程序。
我有一個表格,必須發送電子郵件。 實現這一目標的最佳方法是什么?
您應該查看JavaMail API
此外,您可能需要查看Fancymail ,這是一個簡化JavaMail API使用的小型庫。
用於在此處使用javamail發送簡單純文本郵件的短而臟的復制粘貼
使用自定義smtp主機發送純文本消息的小例子:
Properties props = new Properties();
props.put("mail.smtp.host", "your.mailhost.com");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("mail@from.com"));
msg.setRecipients(Message.RecipientType.TO, new InternetAddress[]{new InternetAddress("mail@to.com")});
msg.setSubject("Subject Line");
msg.setText("Text Body");
Transport.send(msg);
此鏈接可能會有所幫助: http : //www.javabeat.net/tips/33-sending-mail-from-java.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.