<%@ page language="java" import="java.util.Properties,javax.mail.*,javax.mail.internet.InternetAddress,javax.mail.internet.MimeMessage" %>
<%
public class SendAttachment {
public static void main(String args[]) throws Exception {
String host = "smtp.gmail.com";
String from = "123.digit@gmail.com";
String to = "ae@gmail.com";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", host);
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
// Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("JavaMail Attachment");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("hi");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
String filename = "1.csv";
DataSource source = new FileDataSource("d:\\csv\\1.csv");
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);
System.out.println("Msg Send ....");
}
}
i m not able to send mail with this code anyone can make it work