Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having the following code but my mail functionality is not working can anybody please help me...
C#
MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("mail.abc.com");

            mail.From = new MailAddress("abc@abc.com"); //you have to provide your gmail address as from address
            mail.To.Add(txtmail.Text);
            mail.Subject = "Registration";
            mail.Body = "Hello Mr/Mrs" + txtuname.Text + "your password is"+password;

            SmtpServer.Port = 25;
            SmtpServer.Credentials = new System.Net.NetworkCredential("gamil-username", "gmail-passowrd"); //you have to provide you gamil username and password
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
Posted
Updated 31-Jul-14 18:43pm
v2
Comments
kedar001 31-Jul-14 23:54pm    
any Error?

using System.Net;
using System.Net.Mail;
using System.Net.Mime;

...
try
{

   SmtpClient mySmtpClient = new SmtpClient("my.smtp.exampleserver.net");

    // set smtp-client with basicAuthentication
    mySmtpClient.UseDefaultCredentials = false;
   System.Net.NetworkCredential basicAuthenticationInfo = new
      System.Net.NetworkCredential("username", "password");
   mySmtpClient.Credentials = basicAuthenticationInfo;

   // add from,to mailaddresses
   MailAddress from = new MailAddress("test@example.com", "TestFromName");
   MailAddress to = new MailAddress("test2@example.com", "TestToName");
   MailMessage myMail = new System.Net.Mail.MailMessage(from, to);

   // add ReplyTo
   MailAddress replyto = new MailAddress("reply@example.com");
   myMail.ReplyTo = replyto;

   // set subject and encoding
   myMail.Subject = "Test message";
   myMail.SubjectEncoding = System.Text.Encoding.UTF8;

   // set body-message and encoding
   myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>.";
   myMail.BodyEncoding = System.Text.Encoding.UTF8;
   // text or html
   myMail.IsBodyHtml = true;

   mySmtpClient.Send(myMail);
}

catch (SmtpException ex)
{
  throw new ApplicationException
    ("SmtpException has occured: " + ex.Message);
}
catch (Exception ex)
{
   throw ex;
}
 
Share this answer
 
Hi,
Before asking question on Codeproject site ,please search on codeproject.
For this look at this after login
http://www.codeproject.com/search.aspx?q=sending+mail+from+smtp&x=10&y=5&sbo=qa&usfc=false
 
Share this answer
 
Comments
Member 11883585 24-Oct-18 9:08am    
i need code for send mail in html in c#

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