Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends

The following is my code for sending email in contact us page of my website.
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
          msg.From = new MailAddress(emailid.Text);
          msg.To.Add("baskey86@hotmail.com");
          msg.Subject = subject.Text;
          msg.Body = txtBody.Text;
          SmtpClient smtp = new SmtpClient();
          smtp.Host = "smtp.gmail.com";
          smtp.Port = 587;
          smtp.Credentials = new System.Net.NetworkCredential("baskey2@gmail.com", "mygmailpassword");
          smtp.EnableSsl = true;
          smtp.Send(msg);

in my inbox of baskey86@hotmail.com, i just received the message from baskey2@gmail.com. but i want to get mail from email.txt(where somebody enter their email id).how can change that thing.
Posted
Comments
bbirajdar 23-Mar-13 8:58am    
Not possible. Instead send the user's email id inside the email body

1 solution

Try this...
C#
public static bool SendMail(string From, string To, string Subject, string Body)
        {
            MailMessage msg = new MailMessage(From, To, Subject, Body);

            System.Net.NetworkCredential acc = new System.Net.NetworkCredential("Your Email", "Your Password");

            //  server name can be find your mail servers option menu
            SmtpClient srv = new SmtpClient("Your SMTP Server");

            // use this true when your code in a asp.net site and from email is your websites domain email
            srv.UseDefaultCredentials = true;
            srv.Credentials = acc;

            msg.Priority = MailPriority.High;
            msg.IsBodyHtml = true;
            try
            {
                srv.Send(msg);
                return true;
            }
            catch
            {
                return false;
            }
        }


Here,
Your Email= An email address, which was created using your SMPT server. Like "abc@test.com"
Your Password= Password of your email.
Your SMTP Server= A SMPT server of your domain. Like "mail.test.com", here "www.test.com" your domain.
 
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