Send an Auto Response to an email address held in the body

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I receive emails from a web site and the respondents email address is within
the body of the email, the email itself comes through a host somewhere. I
want to be able to send a 'Thanks for your Interest' email as soon as my
inbox receives the request. All the emails that arrive have the same subject
line so I can identify them. I tried Rules and Alerts but that responds to
the sender of the email (the host) not the actual person making the request
from the web site. Basically a simple email to be sent to an email address
that will be found in the body is what I want. Can a script be created to do
this, if so how? Any help very much appreciated. Tim
 
The ItemAdd event of the Inbox tells you when a new item arrives; a sample
is in the VBA help file.

In that event compare the item's Subject property with what you're looking
for. An email address can be found by searching with the InStr function for
a "@" character:

Dim pos&
pos=Instr(Item.Body, "@")

tells you the position of that character. If it's found start at that
position and use the Instr function again to find the right demarcation; you
must know what character that is, usually "'", or ">", or " ".

Then start at pos again and use the InStrRev function, which searches
backwards, that is it will find the left demarcation. If that's done you can
use the Mid function to extract the address.

Call Application.CreateItem to create a new MailItem and then the item's
Recipients.Add function to add the address (write Subject and Body as well)
and call Send.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Thu, 14 Jun 2007 15:02:01 -0700 schrieb Timjohn:
 
Thanks Michael, that looks exactly what I want. Now the awkward bit. I
opened VB from within Outlook, opened Project1 and then ThisOutlookSession,
but I don't know where to put the code, don't really know where to start!
I'll learn as I go but if you have time could you help!

Thanks, Tim
 
Sorry forgot to tell you. I'm running XP Professional, Office 2003
Professional SP2. Just in case that makes a difference. Thanks Tim
 
Copy that into ThisOutlookSession:

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace

Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
ParseMail Item
End If
End Sub

Public Sub ParseMail(Mail As Outlook.MailItem)
' continue
End Sub

In ParseMail, play with the mentioned functions to find and extract the
address from the Mail.Body property.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Fri, 15 Jun 2007 00:07:03 -0700 schrieb Timjohn:
 
Hi Michael,
I've managed to get some vb working well in excel so I'm not thick but I
just can't seem to get my head round this. I know what I want to do and I
think I see what your code says but beyond that I seem to be lost. I've
copied your code into ThisOutlookSession, added an 'if Item.Subject = "Reply
Needed" then msgbox' in the parsemail sub just as a test, restarted Outlook
but nothing happens when mail arrives. I moved the msgbox outside the loop
but still nothing. If you have time your help is very much appreciated.
Warm regards,
Tim
 
Please show how your code actually looks like.

After editing code you need to execute the Application_Startup procedure
manually (place the cursor into it and press f5) or restart Outlook.
Additionally, VBA will be executed only if the security settings are set to
medium or low (toolbar, click Tools/Macro/Security), or if you certify the
project.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>


Am Sat, 16 Jun 2007 02:01:00 -0700 schrieb Timjohn:
 
Hi,

You're being very patient with me and I appreciate it.

Your info allowed me to digitally sign my code and allow the code to run,
the bit I appear to be getting wrong is:

Public Sub ParseMail(Mail As Outlook.MailItem)
MsgBox "email found no check" (this message box now appears OK when mail
arrives)
If Mail.Subject = "Response from your web space" Then
Dim pos&
pos = InStr(Item.Body, "@")
MsgBox "email address found" (this message box doesn't appear)
'going to put the checks in here instr & instrrev etc
'then create the new email (hopefully) etc
End If
End Sub

Thanks, Tim
 
Michael,

Found what I was doing wrong, used Item instead of Mail. Ignore last post,
now trying to create a new mail item & I'll no doubt be back to you, warm
regards, Tim.
 
Michael, you are a STAR!!

Got it working great. Thank you very much.

Last question (I hope) is there a quick easy way to confirm that the
extracted string contains a valid email address?

Again many, many thanks,
Tim.
 
THere's no single function which would tell you that. Instead, you can check
some issues:
- must contain '@'
- must have a '.' after '@'
- must after two to four characters after that dot
- additionally you can check for some invalid characters (whcih I don't know
ad hoc)


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>


Am Sat, 16 Jun 2007 04:49:00 -0700 schrieb Timjohn:
 
Hi Tim,

I HAve looked over this post and your original issue is exactly the problem
I am about to encounter. My VB is terrible and I don't have much time to try
and figure out how to create this code. Do you think it would be possible to
email me or post the code so I could copy it. I would greatly appreciate this.

Thank you very much

Eric Jouseau
 
Back
Top