Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
string name = txt_name.Text;
string emailfrom = txt_email.Text;
string subject = txt_subject.Text;
string msg = txt_msg.Text;
string emailid;
emailto = "example@hotmail.com";
string emailpassword;
emailpassword = "password";

NetworkCredential loginInfo = new NetworkCredential(emailto , emailpassword);
MailMessage message = new MailMessage();
message.From = new MailAddress(emailfrom);
message.To.Add(new MailAddress("example@hotmail.com"));

message.Subject = subject;
message.Body = msg;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("localhost", 587);
client.EnableSsl = false;
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = loginInfo;
client.Send(message);
Posted
Comments
j snooze 29-May-14 17:25pm    
Then why are you using credentials? If you don't have them, don't use them.
You can add client.UseDefaultCredentials = false;
remove network credentials. If you smtp requires a password then you can't get a round it or it has to be set to relay your email without a username and password.
karthik Udhayakumar 29-May-14 17:58pm    
:)
Richard MacCutchan 30-May-14 4:51am    
Most servers will not accept email messages unless you have a valid account on that server. There is enough spam generated already.

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