×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




Did not know that Java Mail uses SendMail. 
But here is what you could do to add CC and BCC type recipients. 

message.addRecipient(Message.RecipientType.CC, new
InternetAddress(ccAddress));
Message.addRecipient(Message.RecipientType.BCC, new
InternetAddress(bccaddress));

Where ccaddress and bccaddress are the cc and bcc addresses. 
HTH. 


-----Original Message-----
From: Eric Kempter [mailto:EKempter@xxxxxxxxxxxxxxx] 
Sent: Thursday, May 06, 2004 1:32 PM
To: JAVA400-L@xxxxxxxxxxxx
Subject: sendmail


Newbie question ahead.
I have successfully  implemented JavaMail on our IBM V5R2 iseries (I5/OS).
The JavaMail class uses sendmail to send email but I noticed that there is
no argument for cc or bcc.  I assume that sendmail is a class and contained
in a package.  My question is, how do I determine what (other) arguments
sendmail will accept?  How do I determine what package sendmail is included
in?  The following is the JavaMail source.  Thanks in advance for any
assistance.

/***************************************************************************
****************
        Date       : 11/02/2001
        Programmer : James Zhang
        Desc       : Practice the javamail.
****************************************************************************
****************/
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.*;

public class JavaMailMIME {
  public static void main (String args[]) throws Exception {
        
    String from     = args[0];
    String to       = args[1];
    String replyTo  = args[2];
    String subject  = args[3];
    String text     = args[4];
        short returnCode = 0;   
        try{
                returnCode = sendMail(from,to,replyTo,subject,text);    
        }catch(Exception e){
                e.printStackTrace();
        }
}

  public static short sendMail (String from, String to, String replyTo, 
                                String subject,String text) throws Exception
{
        try{    
                //get the properties 
                FileInputStream emailPropertyFile;
                //get the properties 
                Properties emailProperty = new Properties();
                try{
                        emailPropertyFile = new
FileInputStream("JavaMail.properties");
                }catch(FileNotFoundException e){
                        //JZEmail.properties not found
                        return 100;
                }
                emailProperty.load(emailPropertyFile);
                emailPropertyFile.close();
                                  
                //String host = "SMTP.RICAINS.COM";   
                String hostName =
emailProperty.getProperty("email.hostname");   
                String hostType =
emailProperty.getProperty("email.hosttype");   
                                   
        // Get system properties
        Properties systemProperty = System.getProperties();
        
        // Setup mail server    
        systemProperty.put(hostType, hostName);
                
        // Get session
        Session session = Session.getDefaultInstance(systemProperty, null);
                //Session session = Session.getInstance(systemProperty,
null);

 

        // Define message
        MimeMessage message = new MimeMessage(session);
        
                // Set the from address
                message.setFrom(new InternetAddress(from));
        
                // Set the to address
                message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));

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

                // Set the content
                message.setContent(text, "text/html");

                // Set the reply to
                replyTo = replyTo.trim();
                if(replyTo != null && !replyTo.equals("")){
                        InternetAddress ReplyTo[] = new InternetAddress[1];

                        ReplyTo[0] = new InternetAddress(replyTo);
                        message.setReplyTo(ReplyTo);
                }
                
                // Send message
                Transport.send(message);
                        
        }catch(MessagingException me){                  
                // search for the real exception that caused the problem
                Exception realException = me;
                while ( (realException instanceof MessagingException) && 
        
((MessagingException)realException).getNextException() != null) {
                                realException =
((MessagingException)realException).getNextException();
                }
                
                // map the exceptions to error codes
                if (realException instanceof javax.mail.MessagingException) 
                        return 101;
                else if (realException instanceof java.net.ConnectException)

                        return 102;
                else if (realException instanceof
java.net.UnknownHostException) 
                        return 103;     
        
        }catch(Exception e){
        // filename is not found
        //e.printStackTrace();
                return 999;
        }       
    return 0;
  }
}

_______________________________________________
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.