Within the workflow of a form I need to save the submitted data to a file and then attach that file to an email which is then sent to a specified address.
How do I get the file details (ie name and path).
It's a bit of an odd request given that the form data could easily be included in the email body, but I'm just doing what I'm asked (or trying to at least).
In the workflow code you could new up a mail message, and then create a memoru stream to handle the attachment of a file. Something like:
private void SendMyMail() {
using (var msg = new MailMessage())
{
msg.To.Add(new MailAddress("[email protected]"));
msg.From = new MailAddress("[email protected]");
msg.Subject = "Yoursubject";
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Body = "<p>Here's your mail message content";
using (var stream = new MemoryStream())
{
// create attachement content
var fileText = "The text to be attached, probably assembled using a StringBuilder";
var fileBytes = Encoding.UTF8.GetBytes(fileText);
stream.Write(fileBytes, 0, fileBytes.length);
stream.Seek(0, SeekOrigin.Begin);
var contentType = new ContentType
{
MediaType = MediaTypeNames.Application.Octet,
Name = newOnePager.Title + ".txt"
};
var attachment = new Attachment(stream, contentType);
msg.Attachments.Add(attachment);
}
using (var client = new SmtpClient())
{
client.Send(msg);
}
}
}
Working with 'save as file' workflow
Within the workflow of a form I need to save the submitted data to a file and then attach that file to an email which is then sent to a specified address.
How do I get the file details (ie name and path).
It's a bit of an odd request given that the form data could easily be included in the email body, but I'm just doing what I'm asked (or trying to at least).
Any guidance would be awesome.
Hi Nathan,
If you've got some coding skills, this could probably best be achieved through a custom workflow.
You can see documentation on how to create workflows here
In the workflow code you could new up a mail message, and then create a memoru stream to handle the attachment of a file. Something like:
Regards
Jesper Hauge
is working on a reply...