General discussion

Locked

MAPI programming in VB.NET (URGENT)

By pnakiet ·
Hello friends,
I'm programming MAPI for sending Email from my Application. But now I could not make it successfully.
Because of the method of objMessage.Send(ShowDialog:=False) have a problem. This Error message showed me:

"An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll

Additional information: [Collaboration Data Objects - [E_INVALIDARG(80070057)]]"

I show you my code below for hoping you help me solve this problem:

Public Sub Send_Email()
Dim objSession As Object
Dim objMessage As Object
Dim objRecipient As Object
Dim strMessage As String
Dim strSubject As String
Dim sProfile As String
Dim strRecipient As String

sProfile = "Outlook"
strSubject = "Test sending mail from VB"
strRecipient = "anyone@yahoo.com"
strMessage = "I don't know if I can send mail from my VB application. Now I test this" _
& Chr(13) & Chr(13) & Chr(10) & "PNAKiet"

objSession = CreateObject("mapi.session")
objSession.Logon(profilename:=sProfile, profilePassword:="mypassword", ShowDialog:=True, newSession:=True)
objMessage = objSession.Outbox.Messages.Add

objRecipient = objMessage.Recipients.Add
objMessage.Text = strMessage
objMessage.Subject = strSubject

objRecipient = objMessage.Recipients.Add
objRecipient.Name = strRecipient
objRecipient.Resolve()
objMessage.Send(ShowDialog:=False) 'ShowDialog
MsgBox("Message sent successfully!") 'Log off using the session object.
objSession.Logoff()
End Sub

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums