Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
string name = txt_name.Text;
        string emailfrom = txt_email.Text;
        string subject = txt_subject.Text;
        string ddl_email = DropDownList1.Text;
        string msg = txt_message.Text;
        //string emailid;
        SmtpClient client = new SmtpClient();


        // NetworkCredential loginInfo = new NetworkCredential(emailto, emailpassword);
        MailMessage message = new MailMessage();
        message.From = new MailAddress(emailfrom + '@' + ddl_email, name);
        message.To.Add(new MailAddress("abc@hotmail.com", "name"));
        NetworkCredential cs = new NetworkCredential("abc@hotmail.com", "xyz");
        if (ddl_email == "gmail.com")
        {
            client.Host = "smtp.gmail.com";
            client.Port = 587;
            client.EnableSsl = true;
        }
        else if (ddl_email == "yahoo.com")
        {
            client.Host = "smtp.mail.yahoo.com";
            client.Port = 587;
            client.EnableSsl = false;
        }
        else
        {
            client.Host = "smtp.live.com";
            client.Port = 587;
            client.EnableSsl = false;
        }
        message.Subject = subject;
        message.Body = msg;
        message.IsBodyHtml = true;

        client.UseDefaultCredentials = true;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.Credentials = cs;
        client.Send(message);
Posted
Updated 30-May-14 21:21pm
v2

If your email server requires a password, then it requires a password. And most do, to prevent them being used as spambot delivery systems.

And if it requires a password, you have to provide the password in order to send an email. Like logging in to your bank website, if you don't have the password the system doesn't know it's you and won't let you use the service.
 
Share this answer
 
Simply, you can't send.

That is because the mail providers would not allow you to login and send anything from their Server. This is how everything on internet is authenticated.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900