I have a ASP.NET FormView which allows for inserting of a record into a SQL Server table. How can I have an email be sent from the application once the record is successfully ad
using System.Net.Mail;
using System.Net;
private void SendMail( string targetMail,
string shownTargetName,
string[] attachmentNames) {
var fromAddress = new MailAddress("support@e-volution-software.de", "MailSendingProgram");
var toAddress = new MailAddress(targetMail, shownTargetName);
const string fromPassword = "12345isAbadPassword";
subject = "Your Subject";
body =
@"
Here you can put in any text that will appear in the body
multilined and even in <html>
";
var smtp = new SmtpClient {
Host = "smtp.1und1.de",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress) {
Subject = subject,
Body = body }
) {
foreach(string filePath in attachmentNames[]) {
Attachment attachMail = new Attachment(filePath);
message.Attachments.Add(attachMail);
}
try {
smtp.Send(message);
MessageBox.Show("E-Mail sent!");
} catch {
MessageBox.Show("Sending failed, check your internet connection!");
}
}
}