Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send a .txt file as email from program.

Status
Not open for further replies.

basepointdesignz

Programmer
Jul 23, 2002
566
GB
Is there a good way to be able to email a .txt file from within my program?

For, example, if there is a menu command labelled 'Send as Email', the user click this and outlook express or some other mailer opens and (The bit I'd like to happen more than anything) a 'new mail' email form is automatically opened and the file is automatically attached to it. If this is too tricky then the user will have to attach it him/herself.

Please, any ideas????
 
You do not actually need Outlook, you can send email via MAPI as long as MAPI is installed. The easiest (but least flexible) is to add VB references to Microsoft MAPI Controls. Drop a MAPISession and MapiMail object onto your forms. set the various properties / methods and then send the mail.

Hope this helps,

Chris Dukes
 
That is true, but you can't display the mail when you've created it with Mapi. When using outlook you can show the mail so the user can add something or so. I thought this was needed.

But else you can use Mapi. If this response was usefull to you, please mark it with a Star!
 
Its quite simple when using the MAPI controls to build a form with text boxes for To, Subject, CC, BCC, and a multiline textbox for the message body. You could also set up a listbox and a browse dialog for the adding of attachments.

Then when the SEND button is pressed, move the text contents to the MAPI control and off you go.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Ok, so I've tried the solution given to me by jantie78, and I went to the posted link. They gave me this code.....

Code:
Dim App As Object
Dim Itm As Object

Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
   .Subject = "A tip from vbCode Magician"
   .To = "mail1@get2net.dk; mail2@get2net.dk"
   .Body = "For tips and source visit vbCode Magician"
   .Send
End With

Well, something happened but I don't know what?! It seems that this code send a pre-designated email, with all the attributes (subject, bodytext, etc..) already written at design time - is this true??

What I actually want to happen is that, at run-time, Outlook opens but is not visible and a new mail item appears on screen, allowing the user to add the address, subject, attachments and body text. If this is possible, please help me!!

I was trying to look into using MAPI but I can't seem to find it in the project references - can someone tell me the exact name of the reference I need..

Thanks in advance,

Renegade
 
Based on the posted code, what I suspect is that Outlook sent the message to both your defined recipients with the Subject and Body that you defined.

To automatically add the attachment, and then display the standard outlook form, you could try the following:

Dim App As Object
Dim Itm As Object

Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = "A tip from vbCode Magician"
.To = "mail1@get2net.dk; mail2@get2net.dk"
.Body = "For tips and source visit vbCode Magician"
.Attachments.Add "c:\dir\file.txt", olByValue, 1, "Some Description"
.Display

End With

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks Cajun,

It works!! That was most helpful!! All I need now is to call up a dialog box before the outlook form appears, so that the user can select the file, then it appears as the attachment on the email. Please can I have code for that and some ammended code for the line:

Code:
   .Attachments.Add "c:\dir\file.txt", olByValue, 1, "Some Description"

if it's tricky or not worth while, I'll simply let the user attach the file from the outlook form - what do you think??

Thanks.

Renegade.
 
Everything works fine, thanks. Don't need code for above reply. Thanks anyway...

What I do need however is, how do I go about writing code for a 'Email has been Sent' confirmation message. I sent two emails as test to my hotmail account and my work address, both sent from home. The hotmail one arrived but I never recieved the one to work. How do I know it was sent OK???

Renegade
 
You might try using the .ReadReceiptRequested property, although I have not tried it. In outlook you have an option for a delivery receipt, but I cannot find a simliar property in the automation objects.

Hope you appreciate the hope that we've all provided. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Yeah, thanks Cajun - and thanks to everyone.. I'll try that .ReadReceiptRequested property. Thanks again..

Renegade
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top