ackage
com.zskx.pem.network.app.web.action;
02 |
03 | import java.util.ArrayList; |
04 | import java.util.Properties; |
05 |
06 | import javax.mail.Message; |
07 | import javax.mail.MessagingException; |
08 | import javax.mail.PasswordAuthentication; |
09 | import javax.mail.Session; |
10 | import javax.mail.Transport; |
11 | import javax.mail.internet.AddressException; |
12 | import javax.mail.internet.InternetAddress; |
13 | import javax.mail.internet.MimeMessage; |
14 |
15 | public class
MailT { |
16 | public
static void
main(String[] args) { |
17 | final
String username = "782957903abc@gmail.com" ; |
18 | final
String password = "123369ab" ; |
19 | Properties props =
new Properties(); |
20 | props.put( "mail.smtp.auth" ,
"true" ); |
21 | props.put( "mail.smtp.starttls.enable" ,
"true" ); |
22 | props.put( "mail.smtp.host" ,
"smtp.gmail.com" ); |
23 | props.put( "mail.smtp.port" ,
"587" ); |
24 | Session session = Session.getInstance(props,
new javax.mail.Authenticator(){ |
25 | protected
PasswordAuthentication getPasswordAuthentication(){ |
26 | return
new PasswordAuthentication(username, password); |
27 | } |
28 | }); |
29 | |
30 | try
{ |
31 | Message message =
new MimeMessage(session); |
32 | message.setFrom( new
InternetAddress( "from@no-spam.com" )); |
33 | message.setRecipients(Message.RecipientType.TO, InternetAddress.parse( "782957903@qq.com" )); |
34 | message.setSubject( "Testing Subject" ); |
35 | message.setText( "Dear mail Craler" ); |
36 | Transport.send(message); |
37 | System.out.println( "Done" ); |
38 | }
catch (AddressException e) { |
39 | // TODO Auto-generated catch block |
40 | e.printStackTrace(); |
41 | }
catch (MessagingException e) { |
42 | // TODO Auto-generated catch block |
43 | e.printStackTrace(); |
44 | } |
45 | } |
46 | } |