Link to home
Start Free TrialLog in
Avatar of Phosphor
Phosphor

asked on

Rule to send subject line as text message to phone

Hello experts,

Is there a way to send just the subject line of all incoming messages to my phone by use of a rule or macro?

I don't want to simply forward the subject and body like I can already do using this:

Sub NewSMS(Item As Outlook.MailItem)
    Dim olkMsg As Outlook.MailItem
    If Weekday(Date) = vbTuesday Then
        Set olkMsg = Item.Forward
        'Change the email address on the following line'
        olkMsg.Recipients.Add "5555551212@txt.att.net"
        olkMsg.Send
    End If
Avatar of TheGorby
TheGorby
Flag of United States of America image

I THINK this will work, I haven't tested it.
Sub CheckDay(Item As Outlook.MailItem)
    Dim olkMsg As Outlook.MailItem
    If Weekday(Date) = vbTuesday Then
        Set sSubj = olkMsg.Subject
    End If
End Sub
Sub NewSMS(Item As Outlook.MailItem)
    Dim olkMsg2 As Outlook.MailItem
    Set olkMsg2 = Outlook.Application.CreateItem(olMailItem)
    With olkMsg2
        .To = "5555551212@txt.att.net"
        .Body = sSubj
        .Subject = ""
        .Send
    End With
End Sub

Open in new window

Avatar of Phosphor
Phosphor

ASKER

I get a "Compile error" message,

If Weekday(Date) = vbTuesday Then
        Set sSubj = olkMsg.Subject << the word Subject is highlighted.
Sorry, that's what I get for not testing! This I've tested and should work just fine:
Sub NewSMS(Msg As MailItem)
    
    Dim strID As String
    Dim strSubj As String
    Dim objMsg As Outlook.MailItem
    
    If Weekday(Date) = vbTuesday Then
        strID = Msg.EntryID
        Set olkMsg = Application.Session.GetItemFromID(strID)
        strSubj = olkMsg.Subject
        Set olkMsg = Application.CreateItem(olMailItem)
        With olkMsg
            .To = "5555551212@txt.att.net"
            .Body = strSubj
            .Subject = ""
            .Send
        End With
    End If
    
    Set olkMsg = Nothing

End Sub

Open in new window

Yes, that shows promise, unfortunately my default email is not the account I need to send from.
I am behind an exchange server and need to use my pop3 account to send. Is there a way to specify which account?
So these emails are received via your Exchange account, but you want to send the subject of those emails using your POP3 account?

Or are the emails received using POP3 and sent using POP3 as well? (all within the same POP3 account)
Which version of Outlook are you using?
Yes, my exchange account is my inbox and I have a secondary Pop account.

I'm currently using Outlook 2007.
Well I don't have a copy of '07 to test on, but starting in '07 Outlook is able to use the '.SendUsingAccount' property. Hopefully the example below is correct, if not here are some sites concerning its use:

http://www.pcreview.co.uk/forums/thread-3828711.php
https://www.experts-exchange.com/questions/23170205/Problems-Using-SendUsingAccount-Property.html
http://www.eggheadcafe.com/software/aspnet/35932219/outlook-automation--sendusingaccount-readonly.aspx
Sub NewSMS(Msg As MailItem) 
     
    Dim strID As String 
    Dim strSubj As String 
    Dim objMsg As Outlook.MailItem 
     
    If Weekday(Date) = vbTuesday Then 
        strID = Msg.EntryID 
        Set olkMsg = Application.Session.GetItemFromID(strID) 
        strSubj = olkMsg.Subject 
        Set olkMsg = Application.CreateItem(olMailItem) 
        With olkMsg 
            .To = "5555551212@txt.att.net" 
            .Body = strSubj 
            .Subject = ""
            .SendUsingAccount = "Account Name"
            .Send 
        End With 
    End If 
     
    Set olkMsg = Nothing 
 
End Sub

Open in new window

Some other methods to try:

--  Removing line 17 completely

--  .SendUsingAccount = "address@domain.com"

--  .SendUsingAccount.SmtpAddress = "address@domain.com"
Thanks, I haven't looked at the examples yet.
This looks like the best option, change your account number accordingly.

http://www.outlookcode.com/codedetail.aspx?id=1359
.SendUsingAccount = Application.Session.Accounts(2)

Open in new window

How is the enumeration determined?
I've tried most things I can think of, tried different enums  for .SendUsingAccount = Application.Session.Accounts(2).

Nothing works yet.
Don't know what to do 'cept read more things...
It's a shame I can't test that myself, not knowing is bugging the hell out of me! The only other thing I can think of is something called Outlook Redemption (http://www.dimastr.com/redemption/). I've never used it myself, but from what I understand it adds extra functions and properties to Outlook that allow you to easily manipulate which account to send from, using VBA.
Yeah, I was reading up on that last night. I had heard before that it helps get beyond certain security thresholds but never explored using it.
Though if I could somehow have an action to simply take the subject line, SenderName & ReceivedTime to be dumped into a text file into a directory I could VBScript it no problem...
ASKER CERTIFIED SOLUTION
Avatar of TheGorby
TheGorby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or if you DO want it to overwrite the file, change line 14 accordingly:
Set objFile = objFSO.CreateTextFile(strExportFileName, True)

Open in new window

My plan right now is to take the ReceivedTime variable and replace all filename unfriendly chars to dynamically set a unique filename, My exchange server D/Ls from the pop3 accounts every 15 mins. and there may be 10-15 emails so when they arrive, the folder watcher script should open the newly created text-file and CDO email them as they arrive. After the email is sent, the base file will be either moved -or- deleted. not figured that out yet...

Thanks a bunch!
Thanks, I've never really meesed with VBA because VBS usually handles all my needs. You definitely earned your points...