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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send mail using Visual Baisc

Status
Not open for further replies.

bhavali

Programmer
Apr 8, 2003
9
GB
I need to send mail using visual basic which should have html file as the body of mail any one please help. i am using visual basic not vb.net
 
thank u for ur response i am presently able to send text mail using MAPISession Control i am able to attach file but unable to send the html file as body of the mail more information pls help me
 
You can't create a HTML e-mail with the MAPI controls. Have to use one of the methods I suggested previously. They also require you to generate HTML formatted text to assign to the message body.

Paul Bent
Northwind IT Systems
 
Guys

If you could help a newbie. I need to learn from scratch how to do this.

I am assuming I need to use the API for MAPI but don't know how.

Can anyone help please...?



-----------------
Cogito Ergo Sum
-----------------
 
MAPI are not API they are controls. Add a reference to these controls via the 'Project|Components' menu. Select 'Microsoft MAPI 6.0 Controls' and they will appear in your tool box.

Search this forum and see faq222-179 for information.

A google search on VB and MAPI will also turn up many links. Like the ones below.


zemp
 
>MAPI are not API

Just a point of clarification. MAPI is the Messaging Application Program Interface. The MAPI controls are a wrapper around that API (or, more accurately, around what is more commonly known as Simple MAPI). You can if you like call the Messaging API directly.

However, using the controls is the easiest way to start getiing into this stuff, even though Simple MAPI is getting a bit dated and underpowered in comparison to the various other mailing options as briefly mentioned by paulbent


 
thanks guys,

I'll look into these tomorrow.


-----------------
Cogito Ergo Sum
-----------------
 
Excuse my butting in rudely, but does anyone know if this will this work on a network system using NT4?. I'm trying to find a way of at least putting in an email with attachment into a Lotus Notes Outbox. Many thanks, appologies.
 
thanks Strom, guys.

I got some sample code and read through the articles on the MS website and they all said pretty much the same thing "You can do it" but none went into any details as to "How".

This is what I ended up with, after dropping in the MS MAPI controls:

MAPISession1.DownLoadMail = False
MAPISession1.LogonUI = False
MAPISession1.NewSession = False
MAPISession1.Action = mapSignOn
If MAPISession1.SessionID = 0 Then
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.MsgIndex = -1
MAPIMessages1.RecipType = 1
MAPIMessages1.RecipDisplayName = ("MyAddress@MyDomain.com")
MAPIMessages1.AddressResolveUI = False
MAPIMessages1.ResolveName
MAPIMessages1.MsgNoteText = "My e-mail Body Text Here."
MAPIMessages1.Send False
End If
MAPIMessages1.Action = mapSignOff

But it flops over saying:

"Action only valid for compose buffer.set MsgIndex = -1"

Mmmm... Think I'll sleep on this one.


-----------------
Cogito Ergo Sum
-----------------
 
Guys.

I managed to get the MAPI controls working. Jusy two issues:

1. WHen I check the sent mail it sets the "e-mail Type" to the address used instead of SMTP.

2. I could really do with getting it to send an attachment also.

Any suggestions...?


-----------------
Cogito Ergo Sum
-----------------
 
Here is some MAPI code that I have used. You can see where an attachement is successfully attached.

Code:
      '// Send an Email using the default email address.
      MAPISession1.SignOn
      MAPIMessages1.SessionID = Me.MAPISession1.SessionID
      MAPIMessages1.Compose
      MAPIMessages1.MsgSubject = "Registration - " & App.ProductName
      MAPIMessages1.MsgNoteText = Create_EmailBody
      MAPIMessages1.RecipAddress = "someone@somesite.com"
      MAPIMessages1.ResolveName
      MAPIMessages1.AttachmentIndex = 0
      MAPIMessages1.AttachmentPosition = 0
      MAPIMessages1.AttachmentPathName = App.Path & "\Register.txt"
      MAPIMessages1.AttachmentName = Trim(txtCompany.Text) & ".txt"
      MAPIMessages1.Send
      MAPISession1.SignOff

zemp
 
Thanks Zemp.

I dunno what I'm doing but I still can't crack it.

"Unspecified Error Has Occured" and when I debug, I get the following line:

MAPIMessages1.Send

Grrr...

This is sooo frustrating...!


-----------------
Cogito Ergo Sum
-----------------
 
Hi guys

Just thought I'd let you know I've managed to get it to work but the attachments command doesn't like wildcards.

I have:

.Attachments.Add "C:\Analyser_Output\Output_Data\SS01_Data.dat"

and want to have:

.Attachments.Add "C:\Analyser_Output\Output_Data\*_Data.dat"

Because the systems name will change.


-----------------
Cogito Ergo Sum
-----------------
 
You can use the Dir function to get the exact name;

myFile = Dir("C:\Analyser_Output\Output_Data\*_Data.dat")

That will return the first matching entry. Calling Dir again without parameters will get any further matching items. To get all matching items just loop until Dir returns an empty string.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Thanks John.

I've finally managed to get it working now.

I have to hardcode the recipients into the code. I'd prefer for them to use a text input box and just have myself as CCd but hey - can't have everything.

As the saying goes "We should have that sorted out in the next release"...!


-----------------
Cogito Ergo Sum
-----------------
 
this looks like a pretty good tutorial...


Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I ran through the above tutorial, and everything works fine, but outlook seems to recognize the program as if it was a 'virus'...

"a program is trying to access your address book, this could be a virus"

"a program is trying to send an email on your behalf, this could be a virus"

Is there a better way to do this without getting warning/notice messages?

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Do a forum search on 'redemption'

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top