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);
}
}