//from to cc
var fromEmailString = "[email protected]";
var toEmailString = "[email protected]";
var cc = "[email protected]";
//con string
var login = "smtpuser";
var password = "smtppass";
var server = "mailserver";
int port;
int.TryParse("587", out port); //587 port
bool encryptConnection;
bool.TryParse(project.Variables["crypto"].Value, out encryptConnection);
//message
var messageSubject = "Got error!";
var messageText = "My project X";
//mimimi
var fromAddress = new System.Net.Mail.MailAddress(fromEmailString, fromEmailString);
var toAddress = new System.Net.Mail.MailAddress(toEmailString, toEmailString);
var smtp = new System.Net.Mail.SmtpClient {
Host = server,
Port = port,
EnableSsl = encryptConnection,
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(login, password)
};
var message = new System.Net.Mail.MailMessage(fromAddress, toAddress) {
Subject = messageSubject,
Body = messageText,
IsBodyHtml = true,
};
message.CC.Add(cc);
// Attach
var lst = project.Lists["myFiles"];
for (int i = 0; i < lst.Count; i++){
var anexo1 = lst[i];
if (!string.IsNullOrEmpty(anexo1))
{
var attach = new System.Net.Mail.Attachment(anexo1);
message.Attachments.Add(attach);
}
}
smtp.Send(message);
message.Dispose();