#region Mail Sender
public Result MailGonder(string konu, string mesaj, string kimeAdres, string ilgiAdres, string url = "http://crm.ardsistem.com.tr", Stream attach = null)
{
System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage()
{
//From = new System.Net.Mail.MailAddress("crm@ardsistem.com", "ARD CRM")
From = new System.Net.Mail.MailAddress("latif.altun@ardgrup.com.tr", "TÜRK MAKBUZ")// for gmail
};
//string path = AppDomain.CurrentDomain.BaseDirectory + "email_templates\\eposta_icerik.html";
//string path = "C:\\PROJECTS\\OnMuhasebe\\OnMuhasebeApi\\OnMuhasebeApi\\Common\\email_templates\\eposta_icerik.html";// for gmail
string path = @".\Common\email_templates\eposta_icerik.html";// for gmail
string template = File.ReadAllText(path);
template = template.Replace("{Baslik}", konu);
template = template.Replace("{Icerik}", mesaj);
template = template.Replace("{Url}", url);
template = template.Replace("{Konu}", konu);
string[] kimeAdresler = kimeAdres.Split(',');
foreach (string kime in kimeAdresler)
{
if (kime != string.Empty)
Email.To.Add(kime);
}
string[] ilgiAdresler = ilgiAdres.Split(',');
foreach (string ilgi in ilgiAdresler)
{
if (ilgi != string.Empty && !Email.To.Any(x => x.Address == ilgi) && !Email.CC.Any(x => x.Address == ilgi))
Email.CC.Add(ilgi);
}
if (attach != null)
{
Attachment attachment = new Attachment(attach, "ek.pdf");
Email.Attachments.Add(attachment);
System.Net.Mime.ContentType contype = new System.Net.Mime.ContentType("application/pdf");
contype.Parameters.Add("method", "REQUEST");
}
Email.Subject = konu;
Email.Body = template;
Email.IsBodyHtml = true;
//if (konu.Contains("Kritik"))
//{
// Email.Headers.Add("X-Priority", "1");
//}
using (System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient())
{
try
{
Client.Host = "mail.ardsistem.com";
//Client.Host = "smtp.gmail.com";
Client.Port = 587;
Client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
Client.UseDefaultCredentials = false;
//Client.Credentials = new System.Net.NetworkCredential(Email.From.Address, "ard.grup.123456");
Client.Credentials = new System.Net.NetworkCredential(Email.From.Address, "L460b577A"); // for gmail
Client.EnableSsl = false;
//Client.EnableSsl = true; // for gmail
Client.Send(Email);
Result sonuc = new Result(true, "Şifreniz mail adresinize gönderilmiştir.", null);
return sonuc;
}
catch (Exception ex)
{
Result sonuc = new Result(false, ex.Message + "İşlem sırasında hata oluştu", null);
return sonuc;
}
}
}
#endregion