The Artima Developer Community
Sponsored Link

Java Answers Forum
send a java mail confirmation email message to several recipients

1 reply on 1 page. Most recent reply: Jul 5, 2006 4:11 AM by Joe Parks

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Jim ascroft

Posts: 1
Nickname: jimfromwhe
Registered: Jun, 2006

send a java mail confirmation email message to several recipients Posted: Jun 27, 2006 1:40 PM
Reply to this message Reply
Advertisement
Hi All,
I have the following method to send a confirmation email message from
within a web app which is working. I would like to send the message to
3 or 4 different email addresses. Could anyone provide the format for
the Bcc Ccc recipients or any other way of sending it to multiple
people?

Thanks

Jim

public void sendConfirmationEmail(String name,String address,String
basket, String email, String orderInfoID) {

// method to send an e-mail via SMTP
// (if no authentication is required from the mailserver)
boolean loggedIn = getLoggedIn();

String from = "w...@woo.com";
String to = email+",c...@woo.com";
String mailserver = "mail.woo.com";

log("To address is: "+to);
log("About to try and Email details: To: "+email+" Firstname: "+name);

try {
log("In the Email try");
SmtpClient client = new SmtpClient( mailserver );
log("Got client");

client.from(from);
client.to(to);

log("Set the client from and to - About to create the print stream");

java.io.PrintStream message = client.startMessage();
log("Started message");
message.println("To: " + to);
// TODO: set the subject line
message.println("Subject: Order Details - Woo Widgets Order");
// TODO: set the body of the message

message.println("Hello "+name+",\nThanks for your order with Focal
Point Furniture Online.\n\nPlease check that the following information
is correct and keep this Email for your records.\n\n");
message.println("Your Name: " +name+"\n");
message.println("YourAddress: " + address+"\n");
message.println("Your Order ID is: " +orderInfoID+"\n\n");
message.println("Your Order detail: " +basket+"\n\n");

if (loggedIn){
message.println("If any of these details are incorrect please log in to
http://www.woo.co.uk to ammend.\nThanks for your
order.\n\nRegards,\nJames Woowoo");

}else{

message.println("If any of these details are incorrect please telephone
01573228393 or Email correctOr...@woo.co.uk to rectify.\nThanks for
your order.\n\nRegards,\nJames Woo");
}

client.closeServer();
log("Confirmation message is sent!!!");
} catch (java.io.IOException ex) {

// in the case of an exception, print a message to the output log
log("ERROR SENDING EMAIL:"+ex);


Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: send a java mail confirmation email message to several recipients Posted: Jul 5, 2006 4:11 AM
Reply to this message Reply
SmtpClient does not support "advanced" addressing. It is a very (Sun-internal) simple wrapper class. You should use the JavaMail API. There's a tutorial at java.sun.com. The specific piece you want is:
http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailSending

String host = ...;
String from = ...;
String to = ...;
 
// 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);
message.setFrom(new InternetAddress(from));
// See http://java.sun.com/products/javamail/javadocs/javax/mail/Message.RecipientType.html
message.addRecipient(Message.RecipientType.TO, 
  new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
 
// Send message
Transport.send(message);

Flat View: This topic has 1 reply on 1 page
Topic: Null Value for JFormattedTextField Previous Topic   Next Topic Topic: purchase

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use