MailAddressCollection addresses error on sending mail with

while using to send email in, had encountered the following error:

System.ArgumentException: The parameter 'addresses' cannot be an empty string. Parameter name: addresses at System.Net.Mail.MailAddressCollection.Add(String addresses) at SendMail.btnSend_Click(Object sender, EventArgs e)

MailMessage mailMessage = new MailMessage();


                mailMessage.From = new MailAddress(txtSender.Text, "asdasda");  
                  //      mailMessage.From = txtSender.Text;
                  //      mailMessage.To = txtReceiver.Text;
                  //      mailMessage.Cc = txtCc.Text;
                  //      mailMessage.Bcc = txtBcc.Text;
                        mailMessage.Subject = txtSubject.Text;
                        mailMessage.Body = txtBody.Text;

                List<string> lststring = new List<string>();


                MailAddressCollection collection = new MailAddressCollection();

                collection.Add(new MailAddress(txtReceiver.Text));

not sure whether it will use one address or many addresses, if required many addresses, it may required list collection, but the list collecton could not be enter to collection.Add,
therefore, tried the single address, as stated in other forum, but the error is still there
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hiran DesaiSolution ArchitectCommented:
Your mail message is type of what?
1) System.Net.Mail.MailMessage
2) System.Web.Mail.MailMessage
doramail05Author Commented:
previously used 2)

now use 1) after reading forums, for testing
Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Hiran DesaiSolution ArchitectCommented:
Is it reference site or you are pointing to a problem you posted there?
doramail05Author Commented:
no, not sure, but i was working on the source file found that,
doramail05Author Commented:
just that it could not send the attachment but only the email

error :
System.IO.IOException: The process cannot access the file 'C:..\Websites\SendEmailwithAttachment\timesheet.xlsx' because it is being used by another process.
i guess this works:

eventhough it is checked from the task manager it is not running there,

            var smtp = new SmtpClient
                Host = "",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential("", "pwd"),
            using (var message = new MailMessage("", "")
                Subject = "sadsasdaad",
                Body = "assadsadsada",




             //   string strFileName = null;

                if (inpAttachment2.PostedFile != null)
                    HttpPostedFile attFile = inpAttachment2.PostedFile;
                    int attachFileLength = attFile.ContentLength;
                    if (attachFileLength > 0)
                        strFileName = Path.GetFileName(inpAttachment2.PostedFile.FileName);

                        Attachment attach = new Attachment(Server.MapPath(strFileName));

                        //MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
                        //    attach2 = strFileName;


Open in new window

Hiran DesaiSolution ArchitectCommented:
You need to remove memory references to close the file first before trying to access it..

Open in new window


Open in new window

Attachment attach = new Attachment(Server.MapPath(strFileName));

Open in new window

Hope this works
doramail05Author Commented:
hi there,

        notice that there are only, contenttype, contentlength, inputstream, filename, could not really find FileContent

example :

doramail05Author Commented:
solved the problem,

as the code above the attached one is called once before it is used again,

which rectify the problem

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
doramail05Author Commented:
figure out the above code before this causes the problem
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.