Requisitos para enviar E-Mail

Olá, tenho pouca experiência em java e principalmente na parte de envio de email. Gostaria de saber quais sãos os requisitos para enviar um email com o javamail.

Estou com um desktop (máquina local), instalado o jdk e configurado o classpath com os .jar do javamail.

é necessário algum cliente de email ou o java já faz isso? Pois só com essas condições não estou conseguindo rodar.

googlei bastante e não consegui achar essas respostas.

Tks!

Espero que possam te ajudar:

http://www.guj.com.br/article.show.logic?id=21
http://java.sun.com/developer/onlineTraining/JavaMail/contents.html

Colega, segue abaixo um trecho para java mail:

package mailpkg;

import java.util.Date;
import java.util.Properties;
import javax.mail.Transport;
import javax.mail.Session;
import javax.mail.MessagingException;
import javax.mail.Message;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class BeanEMail
{
	private String de = "";
	private String para = "";
	private String assunto = "";
	private String mensagem = "";

	public static Properties props = null;
	public static Session sessao = null;

	static
	{
		props = System.getProperties();
		props.put("mail.smtp.host", "localhost");
		props.put("mail.smtp.auth", "true");

    props.put("proxySet", "false");

		sessao = Session.getInstance(props, new Autenticar("seuemail@dominio", "senha"));
	}

	public void setPara(String para)
	{
		this.para = para;
	}

	public void setDe(String de)
	{
		this.de = de;
	}

	public void setAssunto(String assunto)
	{
		this.assunto = assunto;
	}

	public void setMensagem(String mensagem)
	{
		this.mensagem = mensagem;
	}

	public void sendEmail() throws Exception
	{
		if (!verificaCampos())
			throw new Exception("Falha: verifique os campos");

		try
		{
			MimeMessage msg = new MimeMessage(sessao);

			msg.setRecipient(Message.RecipientType.TO, new InternetAddress(this.para));
			msg.setFrom(new InternetAddress(this.de));
			msg.setSubject(this.assunto);

			msg.setSentDate(new Date());
			msg.setContent(mensagem, "text/html");
			Transport.send(msg);
		}
		catch (MessagingException e)
		{
			throw new Exception("Erro de encaminhamento: " + e.getMessage());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public boolean verificaCampos()
	{
		if ( this.de.trim().equals("") ||
			 this.para.trim().equals("") ||
			 this.assunto.trim().equals("") ||
			 this.mensagem.trim().equals("") )
		{
			return false;
		}

		if ( this.de.indexOf("@") == -1 ||
			 this.de.indexOf(".") == -1	||
			 this.para.indexOf("@") == -1 ||
			 this.para.indexOf(".") == -1 )
		{
			return false;
		}

		return true;
	}
}

Outra classe:

package mailpkg;

import javax.mail.*;

public class Autenticar extends Authenticator
{
	private String usuario;
	private String senha;

	public Autenticar(String usuario, String senha)
	{
		this.usuario = usuario;
		this.senha = senha;
	}

	public PasswordAuthentication getPasswordAuthentication()
	{
		return new PasswordAuthentication(usuario, senha);
	}
}

Espero ser útil.
at.

Obrigado pelas respostas imediatas!

jakefrog,

Já tinha lido esses tutoriais. Porém, não consegui colocar em prática.

leorbarbosa,

Vi os seus fontes, bem bacanas!
O que eu tenho aqui é basicamente isso, só que na hora de rodar está retornando um erro. Compila normal, mas da erro na execução. Segue o fonte:

classpath:

C:\bibliotecas\mail.jar;C:\bibliotecas\dsn.jar;C:\bibliotecas\imap.jar;C:\bibliotecas\mailapi.jar;C:\bibliotecas\pop3.jar;C:\bibliotecas\smtp.jar;C:\bibliotecas\activation.jar

Estou compilando no DOS, javac e java para executar.

[code]import javax.mail.;
import javax.mail.internet.
;
import javax.mail.PasswordAuthentication;
import javax.mail.Authenticator;
import java.util.Properties;

public class Email {

private static final String SMTP_HOST_NAME = "<servidor smtp>";
private static final String SMTP_AUTH_USER = "<email>";
private static final String SMTP_AUTH_PWD  = "<senha>";

public static void main(String[] args) throws Exception{
   new Email().test();
}

public void test() throws Exception{
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host", SMTP_HOST_NAME);
    props.put("mail.smtp.auth", "true");
	
    Authenticator auth = new SMTPAuthenticator();
    Session mailSession = Session.getDefaultInstance(props, auth);

    Transport transport = mailSession.getTransport();

    MimeMessage message = new MimeMessage(mailSession);
    message.setContent("This is a test", "text/plain");
    message.setFrom(new InternetAddress("<email>"));
    message.addRecipient(Message.RecipientType.TO,
         new InternetAddress("<email>"));

    transport.connect();
    transport.sendMessage(message,
        message.getRecipients(Message.RecipientType.TO));
    transport.close();		
}

private class SMTPAuthenticator extends javax.mail.Authenticator {
    public PasswordAuthentication getPasswordAuthentication() {
       String username = SMTP_AUTH_USER;
       String password = SMTP_AUTH_PWD;
       return new PasswordAuthentication(username, password);
    }
}

}[/code]

e me retorna o seguinte erro:

Exception in thread “main” java.lang.NoClassDefFoundError: Email
Caused by: java.lang.ClassNotFoundException: Email
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Email. Program will exit.

já não sei mais muito o que fazer. Obs: não tem nenhum client de email configurado na máquina.

Obrigado!

Boa tarde!

Consegui fazer funcioar, só que tive que instalar um client smtp na máquina, o que não resolveu o meu problema, pois não vou poder instalar nda nas máquinas.

Mas consegui com conectar via telnet pelo java.

Abraços.