皮皮网

【list.isempty 源码】【简单登录源码php】【腾讯建站源码获取】mail.jar源码

2024-12-27 14:45:01 来源:heco挖矿源码

1.ant如何发email
2.java实现发送邮件功能

mail.jar源码

ant如何发email

       <to address="***@***"/> <!--将附件html的内容粘贴到邮件--><message><![CDATA[<p>Send email test</p><pre>${ report}</pre><p>Thanks&Regards!</p>]]></message> <!--邮件附件--><attachments><include name="test.log"/></fileset></attachments></mail></target></project>运行的时候可能会报:Failed to initialise MIME mail:javax/mail/MessagingException 这时要加入两个jar包到ant的lib下:mail.jar ,list.isempty 源码 activation.jar 但是运行时还是会报错,因为运行mail的时候不能加classpath它不读不到这两个jar包,

java实现发送邮件功能

       要实现邮件发送功能需要导入包:mail.jar

       /

*

        * Generated by MyEclipse Struts

        * Template path: templates/java/JavaClass.vtl

        */

       package org.demo.action;

       import java.util.Properties;

       import javax.mail.Message;

       import javax.mail.Session;

       import javax.mail.Transport;

       import javax.mail.internet.InternetAddress;

       import javax.mail.internet.MimeMessage;

       import javax.servlet."; // 发送邮件服务器

       String user = "q"; // 邮件服务器登录用户名

       String password = "Queshuwen"; // 邮件服务器登录密码

       String from = "q@nj.headware.cn"; //

       String to = "c@nj.headware.cn"; // 收件人邮件地址

       String subject = demoForm.getBiaoti(); // 邮件标题

       String body = demoForm.getNeirong(); // 邮件内容

       Properties props = new Properties();

       props.put("mail.smtp.host", smtphost);

       props.put("mail.smtp.auth", "true");

       Session ssn = Session.getInstance(props, null);

       MimeMessage message = new MimeMessage(ssn);

       InternetAddress fromAddress = new InternetAddress(from);

       message.setFrom(fromAddress);

       InternetAddress toAddress = new InternetAddress(to);

       message.addRecipient(Message.RecipientType.TO, toAddress);

       message.setSubject(subject);

       message.setText(body);

       Transport transport = ssn.getTransport("smtp");

       transport.connect(smtphost, user, password);

       transport.sendMessage(message, message

       .getRecipients(Message.RecipientType.TO));

       // transport.send(message);

       transport.close();

       return mapping.findForward("succ");

       } catch (Exception e) {

       e.printStackTrace();

       return mapping.findForward("fail");

       }

       }

       }