Email Attachments - Business Process - Send Email

Is there a way to send an attachment inside of a business process?

  • The attachment location/directory is data driven, different for each contact
Like 0

Like

4 comments

Dear John,

 

Here's the method that can be used to implement sending the attachments within business process:

		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<string>("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);
			}
		}

Please note that in this case the file is taken from Attachments and Files tab of the record. If you want to take the file from the external resource you'll need to develop the additional integration.

Lisa

 

Lisa Brown,

Is posible select the sender mailConfiguration? This code take the default email. I need select a shared configuration.

Lisa Brown,

Please feel free to use ESQ to find the mailbox that you need.

https://academy.bpmonline.com/documents/technic-sdk/7-11/use-entitysche…

All user mailboxes are in the MailboxSyncSettings table.

Eugene Podkovka,

Hi, using the script above, is it possible to let the user edit the email message before sending? (like you can do when you use the [ Send email ]?

Show all comments