Home > Forum > Tips&Tricks > Outlook Addin: Create test mail with custom from address

Outlook Addin: Create test mail with custom from address
0

MVP

Hi everyone,

I have the following use case for a customer:
A workflow should be started from Outlook using the (full) Addon. Based on the from address some more information should be retrieved from a custom database and populate other fields. So far so easy, at least in the dev system where I can modify the data in the custom database. This is where my problem/the question starts:

Does anyone have an idea how I can change the stored from address in an msg file/mail?
I will ask the customer to save a test mail as a msg file and send it to me as an attachment. Unfortunately this may take some time and I would prefer to fiddle with a .msg file to change the from address, so that I can continue working. :)
Easiest why would be to send a mail from an SMTP server which allows any "from" address, but I don't have one available. :)

Best regards,
Daniel

MVP

I found another way. Create an .eml file with the script below, open it in outlook (1), navigate to the File options (2) and select 'Move to Folder' this will store the mail in the selected folder. Afterwards you can drag & drop the mail on a tile to start a workflow and you have a custom from address. :)

Best reagards,
Daniel

Based on:
https://gist.github.com/matejskubic/dd2b9abf291906fd972a

$mailMessage = New-Object System.Net.Mail.MailMessage

$mailMessage.From = New-Object System.Net.Mail.MailAddress("name@from.dom")
$mailMessage.To.Add("daniel.krueger@cosmoconsult.com")
$mailMessage.Subject = "This is a test mail"
$mailMessage.Body = "Some body with content"
$attach = new-object Net.Mail.Attachment("C:\Temp\advanced_indicator.png")
$mailMessage.Attachments.Add($attach)

$smtpClient = New-Object System.Net.Mail.SmtpClient
$smtpClient.DeliveryMethod = [System.Net.Mail.SmtpDeliveryMethod]::SpecifiedPickupDirectory;
$smtpClient.PickupDirectoryLocation = "c:\temp\";

$mailMessage.Attachments.Add
$smtpClient.Send($mailMessage);
$smtpClient.Dispose()

$mailMessage.Dispose()