Click here to Skip to main content
15,915,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to send email notifications from web application projects?
Posted
Comments
Sergey Alexandrovich Kryukov 21-Apr-13 0:59am    
The question is too vague to discuss it seriously. Notification of what? Do you have a problem of sending e-mail? What is your problem? What have you done so far and where did you stuck?
—SA
pallavi22 21-Apr-13 1:05am    
i have implemented implemntation of graphical password project..i have to send stored database contents to emailid after execution so dat if we forgot password we can refer emailid

1 solution

The sending of the emails will be done on the server part and is similar with the sending emails from desktop or service applications by using methods from
System.Net.Mail
library. Should be something similar with the next source code:

public static void SendEmailMessage(string smtpHost, string smtpEmail, string fromEmailAddress, string toEmailAddress, string subject, string message, string attachmentFile = null)
{
try
{
string[] temp = smtpEmail.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries);
//
// Create and init the MailMessage object.
//
if (fromEmailAddress == null)
fromEmailAddress = temp[0];
//
MailMessage mailMessage = new MailMessage(fromEmailAddress, toEmailAddress, subject, message);
mailMessage.BodyEncoding = System.Text.UnicodeEncoding.Default;
mailMessage.IsBodyHtml = true;
if (attachmentFile != null)
mailMessage.Attachments.Add(new Attachment(attachmentFile));
//
// Create and init the SMTP Client
//
string[] smtpHostData = smtpHost.Split(';');
int port = 25; // 587 - is for Excange server!
if (smtpHostData.Length > 1)
port = int.Parse(smtpHostData[1]);
//
SmtpClient smtpClient = new SmtpClient(smtpHostData[0], port);
smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; //!?
//
if (temp.Length > 1)
smtpClient.Credentials = new System.Net.NetworkCredential(temp[0], temp[1]);
//
// Send the email.
//
smtpClient.Send(mailMessage);
}
catch (SmtpFailedRecipientException ex)
{
LogicEventLog.LogException(ex);
throw new SmtpFailedRecipientException(toEmailAddress);
}
}
 
Share this answer
 
v2
Comments
pallavi22 21-Apr-13 10:48am    
shall i add this code to my project?
Raul Iloc 22-Apr-13 1:00am    
You could use it with some adaptation to your requests. Not that in the code above the SmtpHost stores the URL of the port used by STMP server separated with ";" and I am reading this value from Web.config. Also "smtpEmail" param stores the email and could be also password separated with ";" used for NetworkCredential; also this value are stored in Web.config.

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