Send Email With Attachment in Java
public boolean sendEmailWithAttachment() { // create some properties and get the default Session Properties props = System.getProperties(); props.put("mail.smtp.host", "smtp host address"); props.put("mail.smtp.port", "25"); Session session = Session.getInstance(props, new MailAuthenticator()); try { // create a message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress address = new InternetAddress(to); msg.setRecipient(Message.RecipientType.TO, address); msg.setSubject("Subject"); // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setContent("Body Text", "text/html"); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart();