PC Review


Reply
Thread Tools Rate Thread

Confirmation of Email Sent

 
 
DEI
Guest
Posts: n/a
 
      28th Oct 2008
I have used the .SendObject method in the past to automate Access and
Outlook, i.e. open an email message, populate it, etc. Works fine

However, I am in need of specifiying the 'From' field in the message, so I
am now creating a session, mail item, etc. and defining the
..SentOnBehalfOfName property. Works fine.

However, with the .SendObject method and error trapping, I was able to
determine whether the email was actually sent by the user, and then time
stamp a field in the database. Is there any way of confirming that the email
was sent using the Outlook.Application MailItem? I.e. with the code below?

Dim myOlApp As Outlook.Application
Dim myOlEmail As Outlook.MailItem

Set myOlApp = CreateObject("Outlook.Application")
Set myOlEmail = myOlApp.CreateItem(olMailItem)

Debug.Print myOlEmail.Sent

With myOlEmail
.Subject = "Test"
.To = "to email address"
.Body = "Body"
.SentOnBehalfOfName = "From email address"
.Display
End With

I am open to any ideas/solutions. I can not find away to accomplish both
tasks - populate the 'from' field and confirm that the email was sent, with
one approach.

Thanks,

DEI


 
Reply With Quote
 
 
 
 
Alan Moseley
Guest
Posts: n/a
 
      29th Oct 2008
Try changing your line:-

Dim myOlEmail As Outlook.MailItem

To:-

Dim WithEvents myOlEmail As Outlook.MailItem

You should now be able to handle the Send event of the MailItem and do
whatever you need eg.

Private Sub myOlEmail_Send(Cancel As Boolean)
debug.print "Email to " & myOlEmail.To & " was sent"
End Sub

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"DEI" wrote:

> I have used the .SendObject method in the past to automate Access and
> Outlook, i.e. open an email message, populate it, etc. Works fine
>
> However, I am in need of specifiying the 'From' field in the message, so I
> am now creating a session, mail item, etc. and defining the
> .SentOnBehalfOfName property. Works fine.
>
> However, with the .SendObject method and error trapping, I was able to
> determine whether the email was actually sent by the user, and then time
> stamp a field in the database. Is there any way of confirming that the email
> was sent using the Outlook.Application MailItem? I.e. with the code below?
>
> Dim myOlApp As Outlook.Application
> Dim myOlEmail As Outlook.MailItem
>
> Set myOlApp = CreateObject("Outlook.Application")
> Set myOlEmail = myOlApp.CreateItem(olMailItem)
>
> Debug.Print myOlEmail.Sent
>
> With myOlEmail
> .Subject = "Test"
> .To = "to email address"
> .Body = "Body"
> .SentOnBehalfOfName = "From email address"
> .Display
> End With
>
> I am open to any ideas/solutions. I can not find away to accomplish both
> tasks - populate the 'from' field and confirm that the email was sent, with
> one approach.
>
> Thanks,
>
> DEI
>
>

 
Reply With Quote
 
DEI
Guest
Posts: n/a
 
      4th Nov 2008
Thank you, Alan.

The solution makes a lot of sense, but I am calling the automation code in a
procedure in a separate module (not attached to a form) and it willnot allow
me to add the WithEvents to the dimesion statement (says it is only valid in
an object model).

When I add the automation code the form itself (button_click), I can use add
WithEvents to the statement, but where/how do I add the private sub
procedure? If I add it to the form, I get an error message.

Thanks.

"Alan Moseley" wrote:

> Try changing your line:-
>
> Dim myOlEmail As Outlook.MailItem
>
> To:-
>
> Dim WithEvents myOlEmail As Outlook.MailItem
>
> You should now be able to handle the Send event of the MailItem and do
> whatever you need eg.
>
> Private Sub myOlEmail_Send(Cancel As Boolean)
> debug.print "Email to " & myOlEmail.To & " was sent"
> End Sub
>
> --
> Alan Moseley IT Consultancy
> http://www.amitc.co.uk
>
> If I have solved your problem, please click Yes below. Thanks.
>
>
> "DEI" wrote:
>
> > I have used the .SendObject method in the past to automate Access and
> > Outlook, i.e. open an email message, populate it, etc. Works fine
> >
> > However, I am in need of specifiying the 'From' field in the message, so I
> > am now creating a session, mail item, etc. and defining the
> > .SentOnBehalfOfName property. Works fine.
> >
> > However, with the .SendObject method and error trapping, I was able to
> > determine whether the email was actually sent by the user, and then time
> > stamp a field in the database. Is there any way of confirming that the email
> > was sent using the Outlook.Application MailItem? I.e. with the code below?
> >
> > Dim myOlApp As Outlook.Application
> > Dim myOlEmail As Outlook.MailItem
> >
> > Set myOlApp = CreateObject("Outlook.Application")
> > Set myOlEmail = myOlApp.CreateItem(olMailItem)
> >
> > Debug.Print myOlEmail.Sent
> >
> > With myOlEmail
> > .Subject = "Test"
> > .To = "to email address"
> > .Body = "Body"
> > .SentOnBehalfOfName = "From email address"
> > .Display
> > End With
> >
> > I am open to any ideas/solutions. I can not find away to accomplish both
> > tasks - populate the 'from' field and confirm that the email was sent, with
> > one approach.
> >
> > Thanks,
> >
> > DEI
> >
> >

 
Reply With Quote
 
Alan Moseley
Guest
Posts: n/a
 
      5th Nov 2008
In your VB editor, within the project explorer, right click and insert a new
Class Module (which should be called Class1). Enter the following code (for
example):-
Dim WithEvents myOlEmail As Outlook.MailItem
Dim mySent As Boolean
Public Sub NewMail()
Dim myOlApp As Outlook.Application
Set myOlApp = CreateObject("Outlook.Application")
Set myOlEmail = myOlApp.CreateItem(olMailItem)

With myOlEmail
.Subject = "Test"
.To = "To Email Address"
.Body = "Body"
.SentOnBehalfOfName = "From Email Address"
.Display
End With
End Sub
Private Sub Class_Initialize()
mySent = False
End Sub
Private Sub myOlEmail_Send(Cancel As Boolean)
MsgBox "Sent"
End Sub

Now, whereever you are wanting to run this code from, use the following:-
Dim x As Class1
Set x = New Class1
x.NewMail

Be sure to destroy your objects after use. Hope it helps.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"DEI" wrote:

> Thank you, Alan.
>
> The solution makes a lot of sense, but I am calling the automation code in a
> procedure in a separate module (not attached to a form) and it willnot allow
> me to add the WithEvents to the dimesion statement (says it is only valid in
> an object model).
>
> When I add the automation code the form itself (button_click), I can use add
> WithEvents to the statement, but where/how do I add the private sub
> procedure? If I add it to the form, I get an error message.
>
> Thanks.
>
> "Alan Moseley" wrote:
>
> > Try changing your line:-
> >
> > Dim myOlEmail As Outlook.MailItem
> >
> > To:-
> >
> > Dim WithEvents myOlEmail As Outlook.MailItem
> >
> > You should now be able to handle the Send event of the MailItem and do
> > whatever you need eg.
> >
> > Private Sub myOlEmail_Send(Cancel As Boolean)
> > debug.print "Email to " & myOlEmail.To & " was sent"
> > End Sub
> >
> > --
> > Alan Moseley IT Consultancy
> > http://www.amitc.co.uk
> >
> > If I have solved your problem, please click Yes below. Thanks.
> >
> >
> > "DEI" wrote:
> >
> > > I have used the .SendObject method in the past to automate Access and
> > > Outlook, i.e. open an email message, populate it, etc. Works fine
> > >
> > > However, I am in need of specifiying the 'From' field in the message, so I
> > > am now creating a session, mail item, etc. and defining the
> > > .SentOnBehalfOfName property. Works fine.
> > >
> > > However, with the .SendObject method and error trapping, I was able to
> > > determine whether the email was actually sent by the user, and then time
> > > stamp a field in the database. Is there any way of confirming that the email
> > > was sent using the Outlook.Application MailItem? I.e. with the code below?
> > >
> > > Dim myOlApp As Outlook.Application
> > > Dim myOlEmail As Outlook.MailItem
> > >
> > > Set myOlApp = CreateObject("Outlook.Application")
> > > Set myOlEmail = myOlApp.CreateItem(olMailItem)
> > >
> > > Debug.Print myOlEmail.Sent
> > >
> > > With myOlEmail
> > > .Subject = "Test"
> > > .To = "to email address"
> > > .Body = "Body"
> > > .SentOnBehalfOfName = "From email address"
> > > .Display
> > > End With
> > >
> > > I am open to any ideas/solutions. I can not find away to accomplish both
> > > tasks - populate the 'from' field and confirm that the email was sent, with
> > > one approach.
> > >
> > > Thanks,
> > >
> > > DEI
> > >
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to send an automatic confirmation of email receipt of email Carolyn Microsoft Outlook Discussion 1 2nd Nov 2009 03:35 PM
Confirmation Email =?Utf-8?B?R2FyeSBEb2xsaXZlcg==?= Microsoft Access Form Coding 1 7th Nov 2007 02:17 AM
Email confirmation =?Utf-8?B?U2FzaGE=?= Microsoft Frontpage 3 14th Sep 2006 04:09 PM
Can Frontpage email a confirmation from an email field? =?Utf-8?B?TWF1cmljZQ==?= Microsoft Frontpage 4 8th May 2006 09:10 AM
create confirmation email in vba when email received Microsoft Outlook VBA Programming 1 23rd Jan 2004 03:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:59 AM.