Sending an Email

I would like to add code to send an email when my code is finished executing.  Is there an easy way to do this?  A code example would be great!!!

Thanks.
mjcotterAsked:
Who is Participating?
 
jgravelleConnect With a Mentor Commented:
If you are using Outlook as an Email program you can do the following:
First set a Reference to the Outlook 98 Type library(Project...References)

On your Form_Unload event:

Private Form_Unload

Dim appObj As New Outlook.Application
Dim itemObj As Object

On Error Resume Next

Set itemObj = appObj.CreateItem(olMailItem)

itemObj.To = "someemail@somewhere"

itemObj.Body = "This is the body of the
message"

itemObj.Subject = "This is the Subject"

itemObj.Send

Set itemObj = Nothing
Set appObj = Nothing

End Sub

Hopes this helps!!!
0
 
Éric MoreauSenior .Net ConsultantCommented:
Use the EE search option and look for SMTP. You will have plenty of examples.
0
 
mjcotterAuthor Commented:
I assume I could also attach a file to the mail message.  Do you know what the command would be?

Thanks.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
jgravelleCommented:
Yes you can attach a file to the email message: Add the following to the previous code:

Dim attObj As Outlook.Attachment

Set attObj = itemObj.Attachments.Add(attName)

**Where attName is the full path of the file you are attaching.**

If you have any trouble let me know.

0
 
mjcotterAuthor Commented:
Adjusted points from 100 to 150
0
 
mjcotterAuthor Commented:
Thanks a lot!  You have been very helpful.  Everything has worked like a charm.  Thanks again!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.