Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/GenSMTPMessageDelivery.cs
2022-08-25 18:17:50 +00:00

132 lines
3.9 KiB
C#

using System;
namespace GZTW.AyaNova.BLL
{
#pragma warning disable 1591
/// <summary>
/// SMTP message delivery
/// </summary>
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("AYANVA.CB1052023_c9TZbuFYBd7f");
// 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 = AyaBizUtils.ReplaceBareLineFeeds(Message);//case 4180
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;
}
}
/// <summary>
/// Confirm SMTP server can be connected to as per
/// global settings for notification
/// </summary>
/// <returns></returns>
public static bool ProbeSMTPServer
{
get
{
//case 1382
// Create a mailman object for sending email.
Chilkat.MailMan mailman = new Chilkat.MailMan();
mailman.UnlockComponent("AYANVA.CB1052023_c9TZbuFYBd7f");
// 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
}