|
|
Title | Send mail using MAPI (Mail API) |
Keywords | MAPI, mail, email, sendmail |
Categories | Office, API |
|
|
Use the MAPISession and MAPIMessages controls. When you click the Send button, the program sets the MAPISession's UserName and Password, and signs on to the mail system.
It then composes a mail message using the MAPIMessages control. It fills in the recipient's name and address, subject, and message body. It then calls the control's Send method to send the mail and SignOff to close the mail connection.
On my system, at least, Outlook Express pops up a dialog asking the user to confirm the message. My guess is this is to make it harder to write email viruses.
|
|
Private Sub cmdSend_Click()
On Error GoTo SendErrorMailError
' Sign on to the mail system.
mpsErrorMail.UserName = txtUser.Text
mpsErrorMail.Password = txtPassword.Text
mpsErrorMail.SignOn
' Send the message.
mpmErrorMail.SessionID = mpsErrorMail.SessionID
mpmErrorMail.Compose
mpmErrorMail.RecipDisplayName = txtToName.Text
mpmErrorMail.RecipAddress = txtToAddress.Text
mpmErrorMail.AddressResolveUI = False
mpmErrorMail.MsgSubject = txtSubject.Text
mpmErrorMail.MsgNoteText = txtBody.Text
mpmErrorMail.Send False
' Sign off of the mail system.
mpsErrorMail.SignOff
Exit Sub
SendErrorMailError:
' There was an error sending the mail.
' Just present the message.
MsgBox "Error " & Format$(Err.Number) & _
" sending mail." & vbCrLf & _
Err.Description
Exit Sub
End Sub
|
|
 |
|
|