Добрый день!
Коллеги, может кто-то знает, как реализовать следующую задачу: надо по бизнес-процессу отправить письмо, к которому прикрепить файл из детали Файлы и примечания документа.
Спасибо
Нравится
Добрый!
Ниже метод реализующий отправку E-mail с вложением, файл берется из детали файлы и ссылки раздела.
[csharp]
public static bool SendMail(string mailto, string caption, string message, Guid FileId, string SchemaName, UserConnection userConn) {
SchemaName+="File";
string smtpServer = Terrasoft.Core.Configuration.SysSettings.GetValue(userConn, "SFsmtpServer").ToString();
string from = Terrasoft.Core.Configuration.SysSettings.GetValue(userConn, "SFFrom").ToString();
string password = Terrasoft.Core.Configuration.SysSettings.GetValue(userConn, "SFPassword").ToString();
Stream FileA = null;
string Fname = "";
var esq = new EntitySchemaQuery(userConn.EntitySchemaManager, SchemaName);
esq.AddAllSchemaColumns();
esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Id",FileId));
var coll = esq.GetEntityCollection(userConn);
foreach(var ent in coll) {
FileA = ent.GetStreamValue("Data");
Fname = ent.GetTypedColumnValue("Name");
break;
}
try {
MailMessage mail = new MailMessage();
mail.From = new MailAddress(from);
mail.To.Add(new MailAddress(mailto));
mail.Subject = caption;
mail.Body = message;
mail.IsBodyHtml = true;
if (FileA != null)
mail.Attachments.Add(new Attachment(FileA, Fname));
SmtpClient client = new SmtpClient();
client.Host = smtpServer;
client.Port = 587;
client.EnableSsl = true;
client.Credentials = new NetworkCredential(from.Split('@')[0], password);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(mail);
mail.Dispose();
return true;
} catch(Exception e) {
throw new Exception("Mail.Send: " + e.Message);
}
}
[/csharp]