Package JavaMail into simple Sendmail

zhaozj2021-02-11  168

Package Steeven; / * Calss: SENDMAILAUTHOR: Steeven@kali.com.cnqq: 7461522Date: 11/13 / 2001Notes: Find Samples in main (); if you send mail only from / to intranet, change domain as u nesed.setup: 1. Change Host, Mailfooter * / Import Java.util. *; Import Java.sql. *; Import Javax.mail. *; Import Javax.mail.Internet. *; Import Javax.Activation. *; Public Class Sendmail Extends Common {Public string host = "smtpserver"; // SMTP server static string mailfooter = "/ n / n / n This message is sent by Webmail http: //www/mail.jsp/n/n"; string domain = "Company" ; boolean sessionDebug; Message msg; multipart multipart; public Sendmail () throws Exception {Properties props = System.getProperties (); props.put ( "mail.host", host); props.put ( "mail.transport.protocol" , "SMTP"); session session = session.getDefaultinstance (props, null); // set debug on the session so we can see what is going on // passing false will not echo debug info, and passing true // will. Session.Setde bug (sessionDebug); // Instantiate a new MimeMessage and fill it with the // required information msg = new MimeMessage (session);. msg.setSentDate (new java.util.Date ()); multipart = new MimeMultipart (); msg.setContent (multipart);} public Sendmail (String to, String from, String subject, String body) throws Exception {this (); this.setSendTo (to); this.setFrom (from); this.setSubject (subject) "This.setBody (body);} public sendmail (String [] to, string from, string subject, string body) THROWS Exception {this (); this.setsendto (to); this.setFrom (from); this.setSubject (SUBJECT); this.setBody (body);

} Public void setHost (String host) throws Exception {this.host = host;} void setFrom (String from) throws Exception {msg.setFrom (new InternetAddress (from "@" domain));} void setSendTo (String [] THROWS EXCEPTION {for (int i = 0; i 转载请注明原文地址:https://www.9cbs.com/read-5845.html


New Post(0)