Re: anyone knw javamail
On Apr 21, 7:20 pm, Lew <l...@lewscanon.com> wrote:
renkie wrote:
hi.
i hav made smtp protocol n i had tried 2 send mail but when i run it
my connection gets failed.
can u give me the solution or hav u any project in smtp?
or can you knw how to run such type of program except java filename...
what will be the Mailhost for such type of program?
For Pete's sake, write in English!
And you spelled "Java" wrong.
--
Lew
Yes. English is bad. But that's not the reason to refuse.
Internet is full of Java Mail examples...
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
class SimpleMail {
public static void main(String[] args) throws Exception{
System.out.println("Sending mail...");
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.mymailserver.com");
props.setProperty("mail.user", "myuser");
props.setProperty("mail.password", "mypwd");
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("HTML mail with images");
message.setFrom(new InternetAddress("me@sender.com"));
message.setContent("<h1>Hello world</h1>", "text/html");
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("you@receiver.com"));
transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}
}
Alex.
http://www.myjavaserver.com/~alexfromohio/