Solved

Automated e-mail from VB application

Posted on 2002-06-18
7
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 70

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 11

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

717 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