• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1504
  • Last Modified:

Outlook Macro to send email

I am using Outlook 2002, and would like to create a macro.  I need the macro to modify the currently open email, rewrite the subject line, then send it.

I've already got the code for the subject line modification.  But how do I instruct Outlook to then send the message?


Sub ms()
Set objItem = Application.ActiveInspector.CurrentItem
objItem.Subject = "TEST " & objItem.Subject
End Sub

Open in new window

0
shanepresley
Asked:
shanepresley
  • 4
  • 3
1 Solution
 
David LeeCommented:
Hi, shanepresley.

You have to create a new message reply, or forward in order to send a message.  You cannot send the currently open message as is.  Try this
Sub ms()
    Dim olkMsg As Outlook.MailItem
    Set objItem = Application.ActiveInspector.CurrentItem
    Set olkMsg = objItem.Forward
    With olkMsg
        .Subject = "TEST " & objItem.Subject
        .Recipients.Add "someone@address.com"
        .Send
    End With
    Set olkMsg = Nothing
End Sub

Open in new window

0
 
shanepresleyAuthor Commented:
Hmm that's a bit of a problem.  I was hoping to let the user compose a new message or reply on their own, then the new macro would modify the subject, then send.

No way to accomplish this?
0
 
David LeeCommented:
Sorry, if the message that's open is already a new message, reply, or forward, then it's not necessary to create another.  If that's the case, then this is what you want
Sub ms()
    Set objItem = Application.ActiveInspector.CurrentItem
    With objItem
        .Subject = "TEST " & .Subject
        .Send
    End With
End Sub

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
shanepresleyAuthor Commented:
Excellent, getting closer!  That worked, thanks!  But outlook gives the user a warning, saying that a program is trying to send a message on your behalf.  Any way around that?  
warning.jpg
0
 
David LeeCommented:
That's Outlook's built-in security.  It cannot be turned off, but can be worked around.  Here are the options.


1.  Sign the code.  Here's a link to instructions on doing that: http://msdn.microsoft.com/en-us/library/aa155754(office.10).aspx
2.  Use ClickYes (http://www.contextmagic.com/express-clickyes/), a small utility that'll click the Yes button for you.  It creates a security hole though, since a virus could start sending messages and ClickYes would click the Yes button for it too.  
3.  Use Redemption (http://www.dimastr.com), a COM library that enables code to safely bypass Outlook security.
0
 
shanepresleyAuthor Commented:
Excellent help, thank you!
0
 
David LeeCommented:
You're welcome.  Glad I could be of service.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now