-1

How i can make two hosts from diffrent websites ? I tried like this but it dosen't work. I would like to send e-mails from yahoo, hotmail, gmail, etc.

   private void SendMail()
    {
        try
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress(textBox4.Text);
            message.Subject = textBox2.Text;
            message.Body = textBox3.Text;
            foreach (string s in textBox1.Text.Split(';'))
                message.To.Add(s);
            if (textBox6.Text != "")
            {
                message.Attachments.Add(new Attachment(textBox6.Text));
            }
            SmtpClient client = new SmtpClient();
            client.Credentials = new NetworkCredential(textBox4.Text, textBox5.Text);
            client.Timeout = 10000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Host = "smtp.live.com";
            client.Host = "smtp.gmail.com";
            client.Port = 587;
           client.Port = 465;
            client.EnableSsl = true;
            client.Send(message);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
Ops
  • 115
  • 2
  • 9

3 Answers3

0

You send the mail from one host, then you configure for the other host and send it again from the other (which, by the way, will be very annoying to your users). You can't send through two hosts in the same call to SmtpClient.Send().

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
0

You are doing it in wrong way. you have to either use different SmtpClient object or you can use the already defined once you are done with Send and then set Host and Port and then finally run Send.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
0

I solved that problem by using combobox.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Ops
  • 115
  • 2
  • 9