Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email to yahoo account

How do you send an email to a yahoo account, I can only send to gmail ? I'd like to know why because MY ISP doesn't offer me a POP3 or SMTP address. I don't know anything about mine, if you could tell me a way to investigate then I'll be delightedly thankful.

    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new NetworkCredential("[email protected]", "mypassword");
    smtp.EnableSsl = true;

    MailAddress mailFrom = new MailAddress("[email protected]");
    MailAddress mailTo = new MailAddress("[email protected]");
    MailMessage msg = new MailMessage(mailFrom, mailTo);
    msg.Subject = "Test";
    msg.Body = textBox1.Text;
    smtp.Send(msg);
like image 605
Pevus Avatar asked Aug 29 '11 02:08

Pevus


2 Answers

You should set your SmtpClient to whatever your outgoing SMTP server is. The code that is successfully sending to GMail is using Google's SMTP server directly. That's OK and is a bit quicker when you're sending to GMail, but they won't want to relay to Yahoo for you. To do so would invite abuse by spammers.

You can find out what your outgoing SMTP server is by looking in the settings of your email client, or by looking at the tech support website for your ISP.

Alternatively you can send directly to yahoo's SMTP server. You'll need to find out what it is. "dig mail.yahoo.com MX" on a *NIX or Mac OS X system will tell you, but to do it automatically you will need to write the code to do a DNS lookup of their MX record.

Some ISPs do not permit outgoing mail to be sent to any SMTP server other than the one that's provided by the ISP. They do that to keep spammers contained. If that's the case you won't be able to talk directly to yahoo's SMTP server, you'll need to talk to your ISPs.

like image 90
Mike Crawford Avatar answered Sep 17 '22 19:09

Mike Crawford


In your code you are using your GMail credentials to connect to the mail server, but see the following.. you are trying to send from Yahoo to GMail.. not from GMail to Yahoo...

MailAddress mailFrom = new MailAddress("[email protected]");
MailAddress mailTo = new MailAddress("[email protected]");

If you want to do this you should connect to the Yahoo server with it's credentials..

Thanks...

like image 38
Prabath Siriwardena Avatar answered Sep 19 '22 19:09

Prabath Siriwardena