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.
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: