Solved

Automated e-mail from VB application

Posted on 2002-06-18
7
126 Views
Last Modified: 2010-05-02
I'm using the following code line to open Outlook with a new message containing a To: address and subject line.

ShellExecute Me.hwnd, "Open", "MailTo:myname@mailserver.com?Subject=A certain subject line", "", "", 0&


It works fine, but I'd like to be able to specify an attachment also, so the user has as little to do as possible. Is there a way to do this?

Thanks.
0
Comment
Question by:rdolivaw
7 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7090013
Here is some code that will open Outlook and mail with attachments

Sub Email()
   
    Dim objOL As Object
    Dim objEMail As Object
   
    Set objOL = CreateObject("Outlook.Application") 'opens Outlook
   
    Set objEMail = objOL.CreateItem(olMailItem) ' opens new email
    With objEMail
        .Recipients.Add "me@me.com" 'recipient's email address
        .Subject = "Your details " & x 'subject of the email
        .Body = "Details"
        'To send an attachment
        .Attachments.Add ("C:\my documents\file.txt")
        .Send
    End With
   
    Set objEMail = Nothing
       
End Sub

This should do it if I did not forget anything.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7090210
have a look at this free an easy mail object: http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 10

Accepted Solution

by:
arana earned 50 total points
ID: 7090213
outlook supports file attachments via shellexecute, but other mailers probably dont support it:

pCh = "mailto:myname@mailserver.com?subject=your_subject&body=your_body&file=" & chr(34) & "c:\autoexec.bat" & chr(34)


ShellExecute Me.hwnd, "Open", pCh, "", "",
0&
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090378
Listening...
0
 

Author Comment

by:rdolivaw
ID: 7090650
arana:

Thanks for the help. The other two were extremely helpful, too, but since all my users have Outlook as their default e-mail program, your solution was easier than those.

Thanks to you other responders, too. Most helpful and interesting information.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090714
Arana, i did try your code but i didn't get any attachment.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090720
Sorry, i did try with Outlook Express ;)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now