[英]How to send email from a java web app
I have a java web application sitting on Tomcat/Apache. 我有一个坐在Tomcat / Apache上的java Web应用程序。
I have a form which has to send email. 我有一个表格,必须发送电子邮件。 What is the best way to get this working. 实现这一目标的最佳方法是什么?
I suppose these threads did appear when you posted your question: 我想当你发布你的问题时,这些线程确实出现了:
Sending mail from java 从java发送邮件
How do I send an e-mail in Java? 如何用Java发送电子邮件?
How can I send an email by Java application using GMail, Yahoo, or Hotmail? 如何使用GMail,Yahoo或Hotmail通过Java应用程序发送电子邮件?
You should look at JavaMail API 您应该查看JavaMail API
Additionally, you may want to look at Fancymail , a small library to simplify usage of JavaMail API. 此外,您可能需要查看Fancymail ,这是一个简化JavaMail API使用的小型库。
Short and dirty copy-and-paste for sending a simple plain text mail message using javamail here 用于在此处使用javamail发送简单纯文本邮件的短而脏的复制粘贴
Tiny example of sending a plain text msg, using custom smtp host: 使用自定义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.