java GMAIL smtp with attach

Joined
Dec 20, 2010
Messages
4
Reaction score
0
Hello guys how to modify this code i want to attach file but ican please help here is my code

import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
public class Main {
public static void main(String[]args){
try{
String SMTP_HOST_NAME = "smtp.gmail.com";
int SMTP_HOST_PORT = 465;

String SMTP_AUTH_USER = "(e-mail address removed)";
String SMTP_AUTH_PWD = "******";
String SMTP_MailTo = "(e-mail address removed)";
String SMTP_Subject = "this is a subject";
String SMTP_Body = "this is a body text";

Properties props = new Properties();
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.host", SMTP_HOST_NAME);
props.put("mail.smtps.auth", "true");
props.put("mail.smtps.quitwait", "false");
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject(SMTP_Subject);

message.setContent(SMTP_Body, "text/plain"); // text/html
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(SMTP_MailTo));
transport.connect
(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}catch(Exception e){}
}
}


thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top