Erro utilizando javax.mail para envio de mala direta

0 respostas
R

Olá pessoa,

Sou novo aqui no forum e vou postar minha primeira dúvida.
Estou fazendo um programa para enviar email (usei como base um artigo que achei aqui no forum) e está dando o seguinte erro:

Exception in thread “main” java.lang.Error: Unresolved compilation problems:
Access restriction: The type Session is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext\mail.jar
Access restriction: The type Session is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext\mail.jar
Access restriction: The method getInstance(Properties, Authenticator) from the type Session is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext\mail.jar
MimeMessage cannot be resolved to a type
MimeMessage cannot be resolved to a type
InternetAddress cannot be resolved to a type
Access restriction: The type Message is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext\mail.jar
Access restriction: The type Message.RecipientType is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext\mail.jar
Access restriction: The field TO from the type Message.RecipientType is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext\mail.jar
InternetAddress cannot be resolved to a type
Access restriction: The type Transport is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext\mail.jar
AddressException cannot be resolved to a type
Access restriction: The type MessagingException is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext\mail.jar

at SendMail.main(SendMail.java:13)

Segue também o código fonte:

import java.util.Properties;

import java.util.Date;

import javax.mail.<em>;

import com.sun.mail.</em>;
public class SendMail

{

public static void main(String [] args) throws Exception

{

Properties p = new Properties();

p.put(mail.host, smtp2.locaweb.com.br);

Session session = Session.getInstance(p, null);
MimeMessage msg = new MimeMessage(session);

try {

msg.setFrom(new InternetAddress([email removido]));

msg.setRecipient(Message.RecipientType.TO, new InternetAddress([email removido]));

msg.setSentDate(new Date());

msg.setSubject(“assunto da mensagem”);

msg.setText(“corpo da mensagem”);

Transport.send(msg);

}

catch (AddressException e) {

// nunca deixe catches vazios!

}

catch (MessagingException e) {

// nunca deixe catches vazios!

}

}

}

Abraços

Criado 14 de abril de 2011
Respostas 0
Participantes 1