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



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) {
			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.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");
			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;
				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 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.…

All user mailboxes are in the MailboxSyncSettings table.

Log in or register to comment