The sun.net.smtp classes are not available
on all platforms (it’s not in mine). That code is not portable
(which is why we use Java isn’t it)! The Java way to send emails is
using the JavaMail API. He could just as easily use JavaMail by providing
“mailhost.worldnet.att.net” as his server, without using these
non-standard classes. However, I’m assuming he would probably run
into some sort of firewall issue with trying to contact an SMTP server outside
the network (that’s usually the case).
-----Original Message-----
From: Jeykumar, Nattamai S.
(LNG-DAY) [mailto:nattamai.jeykumar@xxxxxxxxxxxxxx]
Sent: Friday, July 09, 2004 11:23
AM
To: Jason Kretzer/STAR BASE
Consulting Inc.
Cc: users@xxxxxxxxxx
Subject: RE: [cinjug-users]
sending email from java
Try the following.
This will send email using the outbox "mailhost.worldnet.att.net".
==============================================================
import
java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.Socket;
import
sun.net.smtp.SmtpClient;
public void
sendEmail(String from, String to, String subject, String message) {
PrintStream out;
SmtpClient send;
try {
send = new
SmtpClient("mailhost.worldnet.att.net"); //Do not spam.
ATT will find you easily
send.from(from);
send.to(to);
out =
send.startMessage();
out.println("From: " + from);
out.println("To: " + to);
out.println("Subject: " + subject);
out.flush();
out.close();
send.closeServer();
} catch (java.io.IOException e) {
System.out.println(e.getMessage());
}
}
=============================================================
All you have to do is find a free outbox provider.
Thanks,
Jey
Kumar
-----Original Message-----
From: Jason Kretzer/STAR BASE
Consulting Inc. [mailto:JKretzer@xxxxxxxxxxxxxxx]
Sent: Friday, July 09, 2004 10:55
AM
To: bmanuel@xxxxxxxxxx
Cc: users@xxxxxxxxxx
Subject: Re: [cinjug-users]
sending email from java
From my original post.
"Unfortunately, I do
not have access to ... SMTP server."
Thanks
though.
-Jason
|
bmanuel@xxxxxxxxxx
07/09/2004 10:53 AM
|
|
To
|
"Jason Kretzer/STAR BASE Consulting
Inc." <JKretzer@xxxxxxxxxxxxxxx>
|
|
cc
|
users@xxxxxxxxxx
|
|
Subject
|
Re: [cinjug-users] sending email from java
|
|
You don't need an smtp server installed, you just
need access to one.
Bill Manuel
Sun Certified Web Component Developer
Supply Chain Systems
The Kroger Co.
bmanuel@xxxxxxxxxx
"Jason
Kretzer/STAR BASE
Consulting Inc."
To
<JKretzer@starbas users@xxxxxxxxxx
einc.com>
cc
07/09/2004 10:47
Subject
AM
[cinjug-users] sending email from
java
Hello List,
I have an html form that I would like to have
emailed to a person after
being processed by a servlet. Unfortunately,
I do not have access to nor
permission to install and SMTP server on the box.
Is there a way to do
this in java?
Thanks,
-Jason