views:

194

answers:

4

I am about to give up debugging SMTP servers to send email... My code is the following

 SmtpClient mailClient = new SmtpClient("plus.smtp.mail.yahoo.com", 465);
    mailClient.EnableSsl = true;
    MailMessage message = new MailMessage();
    message.To.Add("[email protected]");
    message.Subject = "permias-tucson-contact-us";
    mailClient.Credentials = new NetworkCredential("[email protected]", "mypassword");
    MailAddress fromAddress = new MailAddress(Email.Text, Name.Text);
    message.From = fromAddress;

    mailClient.Send(message);
+2  A: 

You need to pass login credentials:

mailClient.Credentials = new NetworkCredential(Email.Text, password)
SLaks
so I should know what the sender's password is??
EquinoX
Yes you'll need the username and password. In the case of Yahoo I think the username would be the email address. If the SMTP didn't require authentication then anyone could use it for sending spam.
Dal
okay I did everything and it still gives the same error
EquinoX
+1  A: 

Hi,

Just for a test, try changing the port to 587.

hth, Dave

dave wanta
A: 

I had a similar issue with my Rails Windows development environment. Just FYI I found a simple workaround that works for me: http://programmers-blog.com/2010/09/11/rails-sending-emails-under-windows-xp

A: 

Here's a full working example:

public class Program
{
    static void Main(string[] args)
    {
        using (var client = new SmtpClient("smtp.mail.yahoo.com", 587))
        {
            client.Credentials = new NetworkCredential("[email protected]", "secret");
            var mail = new MailMessage();
            mail.From = new MailAddress("[email protected]");
            mail.To.Add("[email protected]");
            mail.Subject = "Test mail";
            mail.Body = "test body";
            client.Send(mail);
        }
    }
}

Make sure you replace your account and password.

Darin Dimitrov