using System; namespace GZTW.AyaNova.BLL { #pragma warning disable 1591 /// /// SMTP message delivery /// public class GenSMTPMessageDelivery : GenMessageDelivery { public GenSMTPMessageDelivery():base() { // // TODO: Add constructor logic here // } public override bool Deliver() { if(IsValid) { //attempt delivery // Create a mailman object for sending email. Chilkat.MailMan mailman = new Chilkat.MailMan(); mailman.UnlockComponent("SAyanovaMAILQ_46WCmUg3lQ1i"); // Set the SMTP server hostname. mailman.SmtpHost = Host;//"mail.ayanova.com"; //Case 515 mailman.SmtpPort = Port; //case 1136 if (GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPUseSSL) mailman.SmtpSsl = true; if (GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPUseTLS) mailman.StartTLS = true; mailman.SmtpUsername=Login; mailman.SmtpPassword=Password; // Create a simple email. Chilkat.Email email = new Chilkat.Email(); email.Body = Message; email.Subject = Subject; //case 1601 if (ToAddress.Contains(";")) ToAddress = ToAddress.Replace(";", ","); if (ToAddress.Contains(",")) email.AddMultipleTo(ToAddress); else email.AddTo("",ToAddress); email.From = FromAddress; // Send mail. bool success; success = mailman.SendEmail(email); if (success) { this.mFailedDelivery=false; return true; } else { this.mFailedDelivery=true; this.mError=mailman.LastErrorText; return false; } } return false; } public override bool IsValid { get { if(this.Login=="" || this.Password=="" || this.Host=="" || this.ToAddress=="" || this.FromAddress=="" || (this.Message=="" && this.Subject=="")) { this.mFailedDelivery=true; this.mError="SMTP delivery error: One or more required fields empty, undeliverable"; return false; } return true; } } /// /// Confirm SMTP server can be connected to as per /// global settings for notification /// /// public static bool ProbeSMTPServer { get { //case 1382 // Create a mailman object for sending email. Chilkat.MailMan mailman = new Chilkat.MailMan(); mailman.UnlockComponent("SAyanovaMAILQ_46WCmUg3lQ1i"); // Set the SMTP server hostname. mailman.SmtpHost = GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPHostPortionOnly; //Case 515 mailman.SmtpPort = GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPPort; //case 1136 if (GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPUseSSL) mailman.SmtpSsl = true; if (GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPUseTLS) mailman.StartTLS = true; mailman.SmtpUsername = GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPAccount; mailman.SmtpPassword = GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPPassword; //case 1608 bool bCanDeliver = mailman.SmtpNoop(); if (!bCanDeliver) { NotifyDeliveryLog.LogSMTPConnectFailure("Code:" + mailman.LastSmtpStatus.ToString() + "\r\n" + mailman.LastErrorText); } return bCanDeliver; } } } #pragma warning restore 1591 }