I've searched as much as I can, for the previous two weeks between projects, and have yet to find a clear answer (I'm still new to C#, so what's clear to most does not apply.) Our website has a member login and then members can update various contact information for their company. We need an email notification to be sent each time an update is made. Below is the part of the code that sends new submitions and allows updates to current contact info. Like I said, all I need is an email notification to send out everytime the submit button is clicked and all of this code is put to work.

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        OleHelper olHelper = new OleHelper();
        if (hdl.Value == "Yes")
        {
            if (Session["MemberCode"] != null)
            {
                if (ViewState["New"] != null)
                {
                    if (ViewState["New"].ToString() == "N")
                    {
                        string strInsert = "Insert Into MemberContacts (mMemCode,mCoName,mTypeOfContact,mFirstName,mLastName,mTitle,mAddress,mCity,mState,mZip,mPhone,mFax,mEmail,mUtilityTypes,mUpdatedBy) values ";
                        strInsert = strInsert + " ('" + Session["MemberCode"].ToString() + "','" + txtCompanyName.Text.Trim() + "','" + lblTypeContact.Text + "','" + txtFName.Text + "','" + txtLName.Text + "','" + txtTitle.Text + "','" + txtAddress.Text + "','" + txtCity.Text + "','" + txtState.Text + "','" + txtZip.Text + "','" + txtPhone.Text + "','" + txtFax.Text + "','" + txtEmail.Text + "','" + txtUtility.Text + "','" + txtFullName.Text + "')";

                        int result = olHelper.ExecuteNonQuery(null, CommandType.Text, strInsert);
                        if (result > 0)
                        {
                            lblSucc.Text = "Record Successfully Inserted.";
                            hdl.Value = "";
                        }
                        else
                        {
                            lblError.Text = "Failed,Try again";
                        }

                    }
                }
                else
                {
                    string strUpdate = "Update MemberContacts set mCoName = '" + txtCompanyName.Text.Trim() + "', mTypeOfContact = '" + lblTypeContact.Text + "',mFirstName = '" + txtFName.Text + "',mLastName = '" + txtLName.Text + "',mTitle = '" + txtTitle.Text + "',mAddress = '" + txtAddress.Text + "',mCity='" + txtCity.Text + "',mState = '" + txtState.Text + "',mZip = '" + txtZip.Text + "',mPhone = '" + txtPhone.Text + "',mFax = '" + txtFax.Text + "',mEmail = '" + txtEmail.Text + "',mUtilityTypes ='" + txtUtility.Text + "',mUpdatedBy = '" + txtFullName.Text + "' where mMemCode = '" + Session["MemberCode"].ToString() + "' and mTypeOfContact = '" + lblTypeContact.Text + "'";

                    int result = olHelper.ExecuteNonQuery(null, CommandType.Text, strUpdate);
                    if (result > 0)
                    {
                        lblSucc.Text = "Record Successfully Updated.";
                        hdl.Value = "";
                    }
                    else
                    {
                        lblError.Text = "Failed,Try again";
                    }
                }
            }
        }
        else
        {
            lblSucc.Text = "No Changes are made";
        }
    }

Maybe this can help you, I am working in an intranet site and everytime i need to send something i create this static function to do it.
using System.Net.Mail;

public static string SendEmail(string sender, string recipient, string subject, string body)
{

   MailMessage email = new MailMessage();
   MailAddress froma = new MailAddress(sender);
   email.From = froma;
   email.To.Add(recipient);
   email.Subject = subject;
   email.IsBodyHtml = true; //just in case you want to send as html if it is regular text then false.
   email.Body = body;
   SmtpClient smtout = new SmtpClient("yoursmtpserver");
   try
   {
      smtout.Send(email);
      return "Email sent successfully";
   }
   catch (SmtpException ex)
   {
      return ex.Message;
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.