1. Download JavaMail.jar and Jaf Frame (handling multiple formats) javamail: http://java.sun.com/products/javaMail/ jaf: http://java.sun.com/products/javabeans/glasgow/jafa .html2. With your existing free mailbox mail server (requires authentication) 3. Ssendecard.java sends Mail (with attachment) JavaBean4.Email_ca.java authentication JavaBeanPackage NetCard; import java.util.properties; import java .util.Date; import javax.mail *;. import javax.mail.internet *;. import javax.activation *;. public class SendEcard {private String tomail; private String frommail; private String subject; private String content; private String ImageCard; String SMTP = "****"; // Set the mail server public sendecard () {} public string gettomail () {return Tomail;} public void settomail (string tomail) {this.tomail = Tomail;} public string getFrommail () {return frommail;} public void setFrommail (String frommail) {this.frommail = frommail;} public String getSubject () {return subject;} public void setSubject (String subject) {this.subject = subject;} public String GetContent () {Return content;} public void setContent (String content) {this.content = content;} public String getImagecard () {return imagecard;} public void setImagecard (String imagecard) {this.imagecard = imagecard;} public boolean sendMail () {try {Properties P = System.getProperties (); P.PUT ("Mail.smtp.host", this.smtp); P.PUT ("mail.smtp.auth", "true"); // Set to verify mode Session session = Session.getDefaultInstance (p, new Email_ca ( "user name", "password")); MimeMessage msg = new MimeMessage (session); msg.setSentDate (new Date ()); InternetAddress from = new InternetAddress ( Frommail); msg.setfrom (from);
InternetAddress [] address = {new InternetAddress (tomail)}; msg.setRecipients (Message.RecipientType.TO, address); msg.setSubject (this.subject); msg.setText (this.content); Multipart mp = new MimeMultipart ( ); Mimebodypart mbp = new mimebodypart (); fileDataSource fds = new fileDataSource; // Get the attachment itself and incorporates Bodypart Mbp.SetDataHandler (New DataHandler (FDS)); // Get the file name is the same as the Bodypart MBP .SETFILENAME (fds.getname ()); mp.addbodypart (MP); Msg.SetContent (MP); Transport.send (MSG); Return true;} catch (addressexception addr_e) {system.out.println (addr_e.getMessage ()); return false;} catch (MessagingException msg_e) {System.out.println (msg_e.getMessage ()); return false;}}} package netcard; import javax.mail *;. public class Email_ca extends javax.mail .Authenticator {private string user = null; private string pwd = null; public email_ca () {super ();} public void setuser (safwww) (})} public void setpwd String pwd) {this.pwd = pwd;} public Email_ca (String user, String pwd) {super (); setUser (user); setPwd (pwd);} public PasswordAuthentication getPasswordAuthentication () {return new PasswordAuthentication (user, pwd) }}