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

I'm designing a page where an administrator can accept or deny
data that was previously submitted by an user. That data includes the users email id (Editors note: Did you mean address?).
If the admin presses "Deny" an email will be sent to that user with a
static reason.

Can anybody help me?

Thanks you!
Posted
Updated 23-Nov-10 4:02am
v3
Comments
Manfred Rudolf Bihy 23-Nov-10 9:42am    
Do I presume rightly that you already implemented the part where the user submits his/her data? Where does that data go to (database, file, ???). Where exactly are you running into problems?

1 solution

Use the following code in your .cs file

MailHelper.SendMailMessage("fromAddress@yourdomain.com", "toAddress@yourdomain.com", "bccAddress@yourdomain.com", "ccAddress@yourdomain.com", "Sample Subject", "Sample body of text for mail message")


Create a class and add SendMailMessage function in it.

using System.Net.Mail;

public class MailHelper
{
   /// <summary>
   /// Sends an mail message
   /// </summary>
   /// <param name="from">Sender address</param>
   /// <param name="to">Recepient address</param>
   /// <param name="bcc">Bcc recepient</param>
   /// <param name="cc">Cc recepient</param>
   /// <param name="subject">Subject of mail message</param>
   /// <param name="body">Body of mail message</param>
   public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
   {
      // Instantiate a new instance of MailMessage
      MailMessage mMailMessage = new MailMessage();

      // Set the sender address of the mail message
      mMailMessage.From = new MailAddress(from);
      // Set the recepient address of the mail message
      mMailMessage.To.Add(new MailAddress(to)); 
      // Check if the bcc value is null or an empty string
      if ((bcc != null) && (bcc != string.Empty))
      {
         // Set the Bcc address of the mail message
         mMailMessage.Bcc.Add(new MailAddress(bcc));
      }

      // Check if the cc value is null or an empty value
      if ((cc != null) && (cc != string.Empty))
      {
         // Set the CC address of the mail message
         mMailMessage.CC.Add(new MailAddress(cc));
      }       // Set the subject of the mail message
      mMailMessage.Subject = subject;
      // Set the body of the mail message
      mMailMessage.Body = body; 
      // Set the format of the mail message body as HTML
      mMailMessage.IsBodyHtml = true;
      // Set the priority of the mail message to normal
      mMailMessage.Priority = MailPriority.Normal;

      // Instantiate a new instance of SmtpClient
      SmtpClient mSmtpClient = new SmtpClient();
      // Send the mail message
      mSmtpClient.Send(mMailMessage);
   }
}
 
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