Olá pessoal, estou tentando enviar emails e estou encontrando problemas para me autenticar no servidor da uol onde tenho conta... se alguém puder me dizer como fazer.... obrigado...
o código é o seguinte:[color=green]
public class Spammer
{
public static void main (String args[])
{
if (args.length < 4) {
System.out.println("Forma de uso: java Spammer <arquivo msg> <arquivo emails> <from> <subject>");
System.exit(1);
}
try {
System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(args[2]);
System.out.println(args[3]);
postMail(args[0], args[1], args[2], args[3]);
}
catch (MessagingException e) {
System.out.println("Erro: "+ e);
}
}
public static void postMail(String msg_file, String mails_file, String from, String subject) throws MessagingException
{
final boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.uol.com.br");
props.put("mail.smtp.auth", "true");
// create some properties and get the default Session
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
//Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
// Sux, na documentacao que eu tenho diz que da para usar um objeto
// Address simples, mas so funciona com um array de objetos. Entao
// fiz essa gambiarra pq ja tava de saco cheio pra pensar numa
// outra solucao :)
Address to[] = new InternetAddress[1];
msg.setFrom(addressFrom);
msg.setSubject(subject);
StringBuffer mensagem = new StringBuffer();
String linha;
try {
// Arquivo com os enderecos de email ( um por linha )
BufferedReader reader = new BufferedReader(new FileReader(mails_file));
// Arquivo com a mensagem
BufferedReader msg1 = new BufferedReader(new FileReader(msg_file));
// Le todo o conteudo da mensagem a ser enviada
while ((linha = msg1.readLine()) != null)
mensagem.append(linha);
msg1.close();
msg.setContent(mensagem, "text/html");
// Le cada endereco de email e envia
while ((linha = reader.readLine()) != null) {
to[0] = new InternetAddress(linha);
msg.setRecipients(Message.RecipientType.TO, to);
Transport.send(msg);
Thread.sleep(10);
}
}
catch (Exception e) {
System.out.println("Erro: "+ e);
}
}
public static class SMTPAuthenticator extends javax.mail.Authenticator{
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("[email removido]","blablabla...");
}
}
}[/color]
e o erro que está dando é o seguinte:
[color="red"]Erro: javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class javax.mail.SendFailedException: 553 <[email removido]>: Recipient address rejected: Para enviar mensagem pelo UOL, voce deve se identificar. Para isso, clique em "Enviar e Receber Mensagens" (no Outlook Express) ou em "Receber Mensagens" (Get Message, no Netscape) e digite sua senha de acesso ao UOL. [To send messages via UOL, you must identify yourself. To do this, click "Send and Receive Messages" in Outlook Express or "Get Messages" in Netscape, and type in your UOL access password].[/color]