2011-08-03 10 views
3
try 
    {  
     String s1 = "[email protected]"; //sender (from) 
     String s2 = request.getParameter("email");// (from jsp i am taking) 


     String s3 = "testing mail"; (subject) 
     String s4 = "hi.."; (message) 

     Properties props=new Properties(); 

     props.put("mail.smtp.host", "smtp.gmail.com"); 
     props.put("mail.smtp.socketFactory.port", "465"); 
     props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); 
     props.put("mail.smtp.auth", "true"); 
     props.put("mail.smtp.port", "465"); 

     Session session = Session.getDefaultInstance(props,new javax.mail.Authenticator() { 
        protected PasswordAuthentication getPasswordAuthentication() { 
         return new PasswordAuthentication("sender ID","password"); 
        } 
       }); 


     Message message =new MimeMessage(session); 

     message.setFrom(new InternetAddress(s1)); 
     message.setRecipient(Message.RecipientType.TO,new InternetAddress(s2)); 
     message.setSubject(s3); 
     message.setText(s4); 

     Transport.send(message); 
    } 
    catch(Exception ex) 
    { 
     System.out.println("ERROR....."+ex); 
    } 

このコードでは、電子メールアドレスがデータベースから来ているため、JSPからリクエストパラメータとして取得している電子メールを複数にすることができます。JavaMailを使用して複数のレセプションにメールを送信

JavaMailを使用して複数の受信者に同じメールを送信するにはどうすればよいですか?

+0

あなたの質問は正確ですか? –

答えて

3

何も特別なことではありません。複数のユーザーに送信するには、Message.RecipientType.TOInternetAddressの配列を渡す必要があります。

関連する問題