0

I am trying to send an email to Multiple email addresses. But I am getting this exception

A recipient must be specified

at this line

smtp.Send(mail);

I have checked related posts on stackoverflow then I have tried to add this line

 mail.To.Add(new MailAddress(c[0].Address));

but this time exception message says

: Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated

This is my code:

  MailMessage mail = new MailMessage();

            mail.From = new MailAddress(emailFrom);

            MailAddressCollection c = new MailAddressCollection();


            c.Add(new MailAddress("sendto@gmail.com"));

            mail.Subject = "some word";
            mail.Body = "some word";
            mail.IsBodyHtml = true;


            if (c[0].Address.Contains("yahoo"))
            {

                using (SmtpClient smtp = new SmtpClient())
                {

                    smtp.Credentials = new NetworkCredential(emailFrom,PASS);


                    smtp.EnableSsl = true;
                    smtp.Send(mail);
                }
            }
            else if (c[0].Address.Contains("hotmail"))
            {

                using (SmtpClient smtp = new SmtpClient())
                {
                    smtp.Port = 587;
                    smtp.Host = "smtp.live.com";
                    smtp.Credentials = new NetworkCredential(emailFrom, PASS);


                    smtp.EnableSsl = true;
                    smtp.Send(mail);
                }
            }

            else if (c[0].Address.Contains("gmail"))
            {

                SmtpClient smtp = new SmtpClient();

                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;

                smtp.Credentials = new NetworkCredential(emailFrom,PASS)


                smtp.EnableSsl = true;
                smtp.Send(mail);
            }
Uğur Aldanmaz
  • 1,018
  • 1
  • 11
  • 16
user3733078
  • 249
  • 2
  • 11
  • I assume your `emailFrom` has your local network domain's credential, and it has some restrictions to sending mails. If that is the case you might want to get it sorted out from Network admin – Carbine Oct 21 '14 at 10:31
  • 2
    These are 2 separate issues. The first is that an email needs at least one recipient. You fixed this correctly with `mail.To.Add()`. Your issue now is that `smtp.live.com` is rejecting the credentials you are sending it. [This answer](http://stackoverflow.com/a/9851590/1901857) may help – Rhumborl Oct 21 '14 at 10:32
  • I dont understand .I have been working on for hours .I am using gmail account and this code works if i send an email to a gmail account something wrong with hotmail settings.I cant figure out .credentials are correct I have checked while debugging – user3733078 Oct 21 '14 at 11:46

0 Answers0