// ReSharper disable TooManyArguments
string SendEmail(EmailSource runtimeSource, IWarewolfListIterator colItr, IWarewolfIterator fromAccountItr, IWarewolfIterator passwordItr, IWarewolfIterator toItr, IWarewolfIterator ccItr, IWarewolfIterator bccItr, IWarewolfIterator subjectItr, IWarewolfIterator bodyItr, IWarewolfIterator attachmentsItr, out ErrorResultTO errors)
// ReSharper restore TooManyArguments
{
errors = new ErrorResultTO();
var fromAccountValue = colItr.FetchNextValue(fromAccountItr);
var passwordValue = colItr.FetchNextValue(passwordItr);
var toValue = colItr.FetchNextValue(toItr);
var ccValue = colItr.FetchNextValue(ccItr);
var bccValue = colItr.FetchNextValue(bccItr);
var subjectValue = colItr.FetchNextValue(subjectItr);
var bodyValue = colItr.FetchNextValue(bodyItr);
var attachmentsValue = colItr.FetchNextValue(attachmentsItr);
MailMessage mailMessage = new MailMessage();
MailPriority priority;
if (Enum.TryParse(Priority.ToString(), true, out priority))
{
mailMessage.Priority = priority;
}
mailMessage.Subject = subjectValue;
AddToAddresses(toValue, mailMessage);
try
{
// Always use source account unless specifically overridden by From Account
if (!string.IsNullOrEmpty(fromAccountValue))
{
runtimeSource.UserName = fromAccountValue;
runtimeSource.Password = passwordValue;
}
mailMessage.From = new MailAddress(runtimeSource.UserName);
}
catch (Exception)
{
errors.AddError(string.Format("From address is not in the valid format: {0}", fromAccountValue));
return("Failure");
}
mailMessage.Body = bodyValue;
if (!String.IsNullOrEmpty(ccValue))
{
AddCcAddresses(ccValue, mailMessage);
}
if (!String.IsNullOrEmpty(bccValue))
{
AddBccAddresses(bccValue, mailMessage);
}
if (!String.IsNullOrEmpty(attachmentsValue))
{
AddAttachmentsValue(attachmentsValue, mailMessage);
}
string result;
try
{
EmailSender.Send(runtimeSource, mailMessage);
result = "Success";
}
catch (Exception e)
{
result = "Failure";
errors.AddError(e.Message);
}
return(result);
}