Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have one complaint form , with a field name complaint name and another field having complaint description, as soon as I click on a submit button I want that an email is send to the admin stating the problem.
So how to perform that coding of sending email
Posted

 
Share this answer
 
Comments
Krunal Rohit 18-Oct-15 4:50am    
5!
-KR
Abhinav S 18-Oct-15 12:41pm    
Thanks. Though I think your vote is missing! :)
Start by searching for an article on CodeProject, even if trying to Google it would take much time according to you!

The followings articles that I wrote, cover the topic and work in ASP.NET just perfectly:

1. Sending Emails Easily Using ASP.NET Helpers[^]
2. Sending emails over .NET framework, and general problems – using C# code[^]

The later article was written as a version 2 and covers more details about the .NET framework itself, and also covers a few problems that may arise while working with SMTP stuff.
 
Share this answer
 
Comments
Krunal Rohit 18-Oct-15 4:50am    
5!
-KR
Afzaal Ahmad Zeeshan 18-Oct-15 8:00am    
Thank you. :-)
Afzaal Ahmad Zeeshan 18-Oct-15 8:03am    
Perhaps, you forgot to click on the 5 stars. :-)
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();

//Read fromEmail from registery
string fromEmail = Registery.fromAddress;

//Read fromPassword from registery
string fromPassword = Registery.password;

//Read toAddress from registery
string toAddress = Registery.ToAddress;

//Read outgoing server name from registery
string smtpServer = Registery.smtpServer;

//Read port of outgoing server from registery
int port = Convert.ToInt32(Registery.port);

//Read whether enableSSL is true or false from registery
bool enableSSL = Convert.ToBoolean(Registery.enableSSL);

message.From = new MailAddress(fromEmail.ToString());
message.To.Add(toAddress.ToString());
message.Subject = ServiceName + " " + status.ToString();
message.Body = "Service Name :" + ServiceName + Environment.NewLine + "Status :" + status.ToString();
message.IsBodyHtml = true;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

///smtp server and port configured at registry
SmtpClient smtpClient = new SmtpClient(smtpServer, port);

///enable ssl is required for secure connection.It is must be true for gmail server and false for other servers.
smtpClient.EnableSsl = enableSSL;

smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromEmail,fromPassword);
smtpClient.Send(message);
}

catch (Exception ex)
{

Logger.Log("Error In Sending Mail. " + ex.Message + " , " + ex.InnerException, 3);
}
 
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