Ok, now show us the code for sending a multipart mime message with a text
part, and two file attachments.

The javamail code looks like this:

        // create some properties and get the default Session
        Properties props = System.getProperties();
        props.put("mail.smtp.host", host); // your smtp host

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

        try {
            // create a message
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject(subject);

            // create and fill the first message part
            MimeBodyPart mbp1 = new MimeBodyPart();
            mbp1.setText(msgText1);

            // create the second message part
            MimeBodyPart mbp2 = new MimeBodyPart();
            MimeBodyPart mbp3 = new MimeBodyPart();

                   // attach the first file to the message
            FileDataSource fds=new FileDataSource(filename1);
            mbp2.setDataHandler(new DataHandler(fds));
            mbp2.setFileName(filename);
                   // attach the second file to the message
            FileDataSource fds=new FileDataSource(filename2);
            mbp3.setDataHandler(new DataHandler(fds));
            mbp3.setFileName(filename);

            // create the Multipart and its parts to it
            Multipart mp = new MimeMultipart();
            mp.addBodyPart(mbp1);
            mp.addBodyPart(mbp2);
            mp.addBodyPart(mbp3);

            // add the Multipart to the message
            msg.setContent(mp);

            // set the Date: header
            msg.setSentDate(new Date());

            // send the message
            Transport.send(msg);

        } catch (MessagingException mex) {
            mex.printStackTrace();
            Exception ex = null;
            if ((ex = mex.getNextException()) != null) {
                ex.printStackTrace();
            }
        }
--
dIon Gillard, Multitask Consulting
Work:      http://www.multitask.com.au
Play:        http://www.trongus.com

----- Forwarded by dIon Gillard/Multitask Consulting/AU on 14/07/99 03:04
AM -----

  I don't know how you can say that JavaMail is easy
- take a look at that :
> that is required to send a message:

SendMailToRecipient smtr = new
SendMailToRecipient(toAddress,fromAddress,subject,body);

a little bit easy ?

Class goes here (not ideal implementation but bring
an idea how smtp works) :
------------------------------------------------------
import java.io.*;
import java.util.*;
import java.net.*;

public class SendMailToRecipient extends Thread {

String mailTo, mailFrom, subject, body;

  public SendMailToRecipient( String to, String from,
String subject, String body){
    mailTo       = to;
    mailFrom     = from;
    this.subject = subject;
    this.body    = body;
    this.start();
  }

  public void run() {
    String in = "";
    Socket         socket = null;
    PrintWriter    pw     = null;
    BufferedReader br     = null;

    try{
      socket    = new Socket
(c.mailServerIP,25);
      pw        = new PrintWriter
(socket.getOutputStream());
      br        = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
      in = br.readLine();
    }
    catch(Exception e){
    }
    sayToSMTP("mail from:<"+mailFrom+">",pw,br);

    sayToSMTP("rcpt to:<"+mailTo+">",pw,br);
    sayToSMTP("data",pw,br);

    pw.println("From: "+mailFrom);
    pw.println("To:"+mailTo);
    pw.println("Subject: "+subject);
    StringTokenizer st = new StringTokenizer((new
Date()).toString());
    String day    = st.nextToken();
    String month  = st.nextToken();
    String chislo = st.nextToken();
    String time   = st.nextToken();
    String delta  = st.nextToken();
    String year   = st.nextToken();

    pw.println("Date: "+day+", "+chislo+" "+month+"
"+year+" "+time+" "+delta);

    pw.println(body);
    pw.println(".");

    pw.flush();
    try{
      in = br.readLine();
      pw.close();
      br.close();
    }
    catch(Exception e){
    }

  }


  static boolean sayToSMTP(String s, PrintWriter pw,
BufferedReader br){
    try{
      pw.println(s);
      pw.flush();
      String in = br.readLine();
      return true;
    }
    catch(Exception e){
      return false;
    }
  }
-------------------------------------------------------






---Chris Pratt <[EMAIL PROTECTED]> wrote:
>
> I don't know how you can say that JavaMail is too
difficult, this is all
> that is required to send a message:
>
>       try {
>         MimeMessage msg = new MimeMessage(session);
>         Address[] addr =
InternetAddress.parse("[EMAIL PROTECTED]");
>         msg.addFrom(addr);
>
msg.addRecipients(Message.RecipientType.TO,addr);
>         msg.setReplyTo(addr);
>         msg.setSubject("This is a test message");
>         msg.setSentDate(new Date());
>         msg.setText("Testing, 1, 2, 3, Testing");
>         Transport.send(msg);
>       } catch(MessagingException x) {
>         System.err.println("Exception while Sending
Message");
>         x.printStackTrace(System.err);
>       }
>
>     (*Chris*)
>
> ----- Original Message -----
> From: Won, Taewoong <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, July 12, 1999 11:54 PM
> Subject: Servlet
>
>
> > My servlet need to send e-mail message via remote
SMTP servler. The
> environment
> > is Solaris 2.6, ServletExec 2.0, Netscape
Enterprise Server with Sun JDK
> 1.2
> > VM. At first I looked into JavaMail API, but it
is too complicated for our
> > simple needs. Are there any other simple
SMTP-repackage available that I
> can
> > use with minimum modification?
> >
> > Won, Taewoong
> > [EMAIL PROTECTED]
> >
> >
>
___________________________________________________________________________
> > 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
> >
>
>
___________________________________________________________________________
> 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
>

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

___________________________________________________________________________
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




Previous Document


Next Document
Return to View

___________________________________________________________________________
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