Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:38:18+00:00 2026-06-10T03:38:18+00:00

I am sending mail using following code public void send() throws MessagingException { //

  • 0

I am sending mail using following code

public void send() throws MessagingException
    {
        // create some properties and get the Session
        Properties props = new Properties();
        props.put("mail.smtp.host", this.getSMTPServer());

        if( this.getDebugMode() )
            props.put("mail.debug", "true");
        else
            props.put("mail.debug", "false");
        //Comment by Sandip for FIRSTMEDIA-578
        //props.put("mail.smtp.auth", "true");

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

        MimeMessage mail = new MimeMessage(session);

        //Set Mailer string in Header.. 
        mail.setHeader("X-Mailer", this.getMailer() );

        //Set TO Recipients, toList would be of comma separated if multiple addresses are there
        if( this.getTo() != null )
        {
            StringTokenizer st = new StringTokenizer(this.getTo(),",");
            InternetAddress[] recList = new InternetAddress[st.countTokens()];

            for (int r = 0; st.hasMoreTokens(); r++)
                recList[r] = new InternetAddress(st.nextToken().trim());          

            if(recList.length != 0 )
            {
                mail.setRecipients(Message.RecipientType.TO, recList);
            }

        }           


        //Set CC Recipients, bccList would be of comma separated if multiple addresses are there
        if( this.getCc() != null )
        {
            StringTokenizer st1 = new StringTokenizer(this.getCc(),",");
            InternetAddress[] copyList = new InternetAddress[st1.countTokens()];
            for (int c = 0; st1.hasMoreTokens(); c++)
                copyList[c] = new InternetAddress(st1.nextToken().trim());          

            if(copyList.length != 0 )
                mail.setRecipients(Message.RecipientType.CC, copyList);
        }           


        //Set BCC Recipients, bccList would be of comma separated if multiple addresses are there
        if( this.getBcc() != null )
        {
            StringTokenizer st2 = new StringTokenizer(this.getBcc(),",");
            InternetAddress[] bcopyList = new InternetAddress[st2.countTokens()];
            for (int c = 0; st2.hasMoreTokens(); c++)
                bcopyList[c] = new InternetAddress(st2.nextToken().trim());          

            if(bcopyList.length != 0 )
                mail.setRecipients(Message.RecipientType.BCC, bcopyList);
        }   


        // Create a mime message
        mail.setFrom(new InternetAddress(this.getFrom()));
        mail.setSubject(subject);


        //create mulitple parts to added
        Multipart mp = new MimeMultipart();

        MimeBodyPart mbp1 = new MimeBodyPart();

        //messageMIME can be "text/plain" or "text/html" or anything related to mime
        mbp1.setContent(this.getMsgText(),this.getContentType());
        mp.addBodyPart(mbp1);

        //Adding attachments to mail
        if( this.attachmentList != null )
        {
            for(int i=0; i < this.attachmentList.size() ; i++ )
            {
                MimeBodyPart mbp = new MimeBodyPart();
                FileDataSource fds = new FileDataSource((File)this.attachmentList.elementAt(i));
                mbp.setDataHandler(new DataHandler(fds));
                mbp.setFileName(fds.getName());
                mp.addBodyPart(mbp);
            }
        }

        mail.setContent(mp);
        mail.saveChanges();

        mail.setSentDate(new Date());

        // Send the message
        Transport trans = session.getTransport("smtp");
        trans.connect(this.getSMTPServer(), this.getSMTPUsername(), this.getSMTPPassword());
        trans.sendMessage(mail, mail.getAllRecipients());
        trans.close();

    }

With this When mail sending fails to one recipient out of list of recipient all recipient mail send fails.

Is there any change require to send mail to all correct mail recipient from list ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:38:19+00:00Added an answer on June 10, 2026 at 3:38 am

    If you check the Doc, send Message says:
    “Send the Message to the specified list of addresses. An appropriate TransportEvent indicating the delivery status is delivered to any TransportListener registered on this Transport. Also, if any of the addresses is invalid, a SendFailedException is thrown. Whether or not the message is still sent succesfully to any valid addresses depends on the Transport implementation. “

    You can try to:

    • send it onw by one in your code or
    • you can catch the exception SendFailedException and check
      getValidUnsentAddresses to sent to the valid addresses that have
      not been sent.

    I really prefer the second one 🙂

    Check Sent Failed Exception

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code for sending e-mail (gmail) using Java program. I
I'm using the following piece of code in Android to send a mail: Intent
I am sending mail through my application. For that I am using following code.
sending mail along with embedded image using asp.net I have already used following but
I'm sending a simple mail with attachment using SmtpClient but I get this error:
I have send an email using php mailer class. mail was sending successfully but
This is my code to send mail (test code): //sending mail var message =
I am sending emails successfully using following code. But now I want to attach
I am using the following code to send out a Multipart/Alternative HTML and Plain
I'm using the following code from this answer Sending email in .NET through Gmail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.