Hi there,

I'm coding a simple servlet which only sends emails.
and I've got a typical simple sample code below in this email.
I'm wondering why the code doesn't use Store & Folder objects.
If I only wanna send emails, I don't need Store $ Folder ?
I need only Session object ?

now I got a new question here.
If I use only Session, How can I supply my user-id & password for the
SMTP server ? Don't I need user-id & password for SMTP ?
hm...it seems anybody else can use my SMTP server to send bulk emails.

Thank you.

Fumi

//--------- typical simple code------------------
smtpHost = config.getInitParameter("smtpHost");

}

public void doPost(
HttpServletRequest request,
HttpServletResponse response
)
throws ServletException, java.io.IOException {
String from = request.getParameter("from");
String to = request.getParameter("to");
String cc = request.getParameter("cc");
String bcc = request.getParameter("bcc");
String smtp = request.getParameter("smtphost");
String subject = request.getParameter("subject");
String filename = request.getParameter("attach");
String text = request.getParameter("body");

PrintWriter writer = response.getWriter();

if (subject == null)
subject = "Null";
if (text == null)
text = "No message";

text = text + "\n\n Message is processed by Mahesh More by Java SMTP Client";

String status;

try {
// Create the JavaMail session
java.util.Properties properties = System.getProperties ();
if (smtp == null)
smtp = "sbm5501";
properties.put("mail.smtp.host", smtp);
Session session = Session.getInstance(properties, null);

// Construct the message
MimeMessage message = new MimeMessage(session);

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

// Parse and set the recipient addresses
Address[] toAddresses = InternetAddress.parse(to);
message.setRecipients
(Message.RecipientType.TO,toAddresses);

Address[] ccAddresses = InternetAddress.parse(cc);
message.setRecipients
(Message.RecipientType.CC,ccAddresses);

Address[] bccAddresses = InternetAddress.parse(bcc);
message.setRecipients
(Message.RecipientType.BCC,bccAddresses);

// Set the subject and text
message.setSubject(subject);

/**
message.setText(text);

Transport.send(message);

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to