Всем доброго времени суток. Хочу написать программу для рассылки почты всем адресатам которые есть в txt файле. | Код | package Jmail.main;
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.net.PasswordAuthentication; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Date; import java.util.Iterator; import java.util.Properties; import java.lang.*; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage;
public class test {
public static void main(String args[]) throws AddressException, MessagingException, IOException {
// Создание свойств, получение сессии Properties props = new Properties(); props.put("mail.smtp.com" , "smtp.yandex.com");
// Сюда необходимо подставить адрес получателя сообщения String subject = "Testing..."; System.out.println(subject); props.put("mail.transport.protocol","smtp"); props.put("mail.smtp.host","smtp.yandex.ru"); props.put("mail.smtp.auth", "true"); Session session = Session.getInstance(props,new Authenticator(){ protected javax.mail.PasswordAuthentication getPasswordAuthentication(){ return(new javax.mail.PasswordAuthentication("ййй","ййй")); } }); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress("[email protected]")); // String to = "[email protected]"; //********** String to; char t1;
FileInputStream text = new FileInputStream("d:\\alli1.txt"); //После этого получаем канал для этого файла FileChannel ob = text.getChannel(); long razmer_buf = ob.size(); System.out.println("Файл 1.txt имеет размер "+razmer_buf+" байт"); //Выделяем буффер требуемого размера ByteBuffer b = ByteBuffer.allocate((int)razmer_buf); //Считываем файл в буффер ob.read(b); b.rewind(); // for(int i=0; i<razmer_buf;i++){ for(int i=0; i<razmer_buf;i++){ t1=(char)b.get(); to = String.valueOf(t1); to = to.replace( " ", "" );
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Subject","koi8-r"); message.setText("ййй \n\n","koi8-r"); Transport.send(message);
System.out.print(to); text.close(); ob.close(); } System.out.println(); //*************** } } |
выдает ошибку Exception in thread "main" javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 504 5.5.2 Recipient address rejected: need fully-qualified address ошибка в адресе.. хотя System.out.print(to) показывает верный адрес из файла. подскажите в чем дело. З.Ы, с JAVA только начал копаться)
|