Sending an email with Java.

Okay, how would I send an email with Java?As in, say I wanted to sent an email to someone from noreply@sitename.com the same way you can do with a php mailer... How do you do that?
[194 byte] By [Repentlessa] at [2007-11-27 3:59:56]
# 1
Have you even tried : http://www.google.ca/search?hl=en&q=sending+mail+%2Bjava&btnG=Google+Search&meta=?
Aknibbsa at 2007-7-12 9:04:31 > top of Java-index,Java Essentials,Java Programming...
# 2
Yes, but with fake headers. One that doesn't require a previous email account to use. noreply@site.com would not be a real email address.
Repentlessa at 2007-7-12 9:04:31 > top of Java-index,Java Essentials,Java Programming...
# 3
Wait, nevermind.... http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274 tells you how :) Thanks.
Repentlessa at 2007-7-12 9:04:31 > top of Java-index,Java Essentials,Java Programming...
# 4

> Yes, but with fake headers. One that doesn't require

> a previous email account to use. noreply@site.com

> would not be a real email address.

See reply #1, still. Be aware that modern POP3 servers may notice that the address doesn't reconcile with the originating domain, and treat it as spam. You'll also need access to an SMTP server that will relay out of the domain for you

georgemca at 2007-7-12 9:04:31 > top of Java-index,Java Essentials,Java Programming...
# 5

http://java.sun.com/developer/JDCTechTips/2001/tt1023.html

import java.io.*;

import javax.mail.*;

import javax.mail.internet.*;

import javax.activation.*;

public class SendApp {

public static void send(String smtpHost, int smtpPort,

String from, String to,

String subject, String content)

throws AddressException, MessagingException {

// Create a mail session

java.util.Properties props = System.getProperties();

props.put("mail.smtp.host", smtpHost);

props.put("mail.smtp.port", ""+smtpPort);

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

// Construct the message

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));

msg.setSubject(subject);

msg.setText(content);

// Send the message

Transport.send(msg);

}

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

// Send a test message

send("hostname", 25, "joe@smith.com", "sue@smith.com",

"re: dinner", "How about at 7?");

}

}

java_2006a at 2007-7-12 9:04:31 > top of Java-index,Java Essentials,Java Programming...