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 6175309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:54:10+00:00 2026-05-23T23:54:10+00:00

So I am making a program that emails a list of users from a

  • 0

So I am making a program that emails a list of users from a .txt file. Here is what I have so far.

MailAddress from = new MailAddress("testadmin@gmail.com", "MAIL BOT TEST");
        MailAddress to = new MailAddress("testadmin", "Admin");
        MailMessage message = new MailMessage(from, to);

using (StreamReader sr3 = new StreamReader(@"C:\Data\Items\emailItems.txt"))
         {
             string emailList;
             emailList = sr3.ReadToEnd();
             MailAddress bcc = new MailAddress(emailList);
             message.Bcc.Add(bcc);

             Console.WriteLine(emailList);
             MessageBox.Show("" + emailList, "Email List", MessageBoxButtons.OK);
         }

The emailList will not work since it throws an exception and it takes:

MailAddress bcc = new MailAddress("manager1@contoso.com");

Below is how the .txt is formatted. Should I seperate them with comments?

test01@gmail.com
test02@gmail.com

Here is the exception thrown:

{"The specified string is not in the form required for an e-mail address."}

Thanks and Cheers,
Sean.

  • 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-05-23T23:54:11+00:00Added an answer on May 23, 2026 at 11:54 pm

    MailAddress can only take a single address, not a list, so you need to add a MailAddress to Bcc for each recipient.

    Assuming your text file has each e-mail address on a line of its own (and your question suggests it has), try this:

    string[] recipients = File.ReadAllLines(@"C:\Data\Items\emailItems.txt");
    
    string recipient;
    
    foreach (var recipientLine in recipients)
    {
         // Just to take care of leading/trailing spaces and blank lines
         recipient = recipientLine.Trim();
         if (!string.IsNullOrEmpty(recipient))
         {
             MailAddress bcc = new MailAddress(recipient);
             message.Bcc.Add(bcc);   
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a program that import emails from txt files and send a
I have been making a program that creates multiple CSV's from another source CSV
I am making a program that generates a Javascript file. I have never worked
I'm fairly new to C# programming. I am making a program for fun that
I'm making a program that asks for an integer from the user, it then
I'm making a program that connects to a website and downloads XML from it.
I am making a program that solves an equation. I have a variable that
I'm making a program that takes names from the user seperated by commas. The
I'm making a program that will display a few images from a directory beside
I'm making a program that will have a widget that has to be fixed

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.