Google App'ta mail hesabınız var ise aşağıdaki gibi mail gönderebilirsiniz :
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import com.sun.mail.smtp.*;
public class MailSender {
public void sendMail(String address,String subject,String body){
Properties props = new Properties();
props.put("host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("x@x.com"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress(address));
msg.setSubject(subject);
msg.setContent(body, "text/html");
SMTPTransport t = (SMTPTransport)session.getTransport("smtp");
t.setStartTLS(true);
t.connect("smtp.gmail.com", "username", "password");
t.sendMessage(msg, msg.getAllRecipients());
t.close();
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
MailSender ms=new MailSender();
ms.sendMail("test@gmail.com","Test 2",
"Test Maili");
}
}