Javamail + port number

1 resposta
A

Hi all !

Como posso setar o número da porta SMTP utilizando Javamail ?

import java.util.Properties;

import javax.mail.<em>;

import javax.mail.internet.</em>;
public class MailExample {

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

String host = args[0];

String from = args[1];

String to = args[2];
// Get system properties
Properties props = System.getProperties();

// Setup mail server
props.put("mail.smtp.host", host);

// Get session
Session session = Session.getDefaultInstance(props, null);

// Define message
MimeMessage message = new MimeMessage(session);

// Set the from address
message.setFrom(new InternetAddress(from));

// Set the to address
message.addRecipient(Message.RecipientType.TO, 
  new InternetAddress(to));

// Set the subject
message.setSubject("Hello JavaMail");

// Set the content
message.setText("Welcome to JavaMail");

// Send message
Transport.send(message);

}
}

1 Resposta

Rafael_Steil

Voce pode usar o metodo

connect(java.lang.String host,
int port,
java.lang.String user,
java.lang.String password)

que tem em Transport, ou setar a property “mail.smtp.port” para isso.

Rafael

Criado 6 de dezembro de 2002
Ultima resposta 6 de dez. de 2002
Respostas 1
Participantes 2