PDA

View Full Version : [SOLVED:] Button to change subject



ertuu85
02-06-2017, 03:07 PM
Hello, I'm very new to any development for outlook, I mostly do a lot of powershell, so my questions may sound silly.

I want to create a button in outlook for new emails that would change the subject to something like...

$subject = "[encrypt]$subject"

So it would just add the string [encrypt] in front of the existing subject so when sent it willb e encrypted by other services.

Is something like this possible?

skatonni
02-06-2017, 04:42 PM
The mailitem subject is Read/write.
https://msdn.microsoft.com/EN-US/library/office/ff865652.aspx

Rather than the selected item as in the example in the link you could work with an open item.


Option Explicit

Sub prefixSubjectWithEncrypt()

Dim myItem As MailItem
Set myItem = ActiveInspector.CurrentItem
myItem.Subject = "[encrypt]" & myItem.Subject
myItem.Display

End Sub

ertuu85
02-07-2017, 08:39 AM
That works rather well!

I figured how to send it using the send method on the object MyItem



Myitem.send


If the 'to:' field is blank it will error on the send as it's blank, is there an easy way to do a:

if myitem.recipient -eq null
{
msgbox("Need at least one person to send to")
}
else
{
myitem.send
}


Edit: I think i'm looking for the .To method, not recipients

Still no luck with:



Sub prefixSubjectWithEncrypt()

Dim myItem As MailItem
Set myItem = ActiveInspector.CurrentItem
myItem.Subject = "[encrypt]" & myItem.Subject
myItem.Display

If myItem.To Is Nothing Then
MsgBox "You need at least one recipient"
Exit Sub
End If

myItem.Send

End Sub


Type mismatch

skatonni
02-07-2017, 11:46 AM
To is a string.


If myItem.To = "" Then