472,101 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

Send email through mapi

I am using the following code for sending email through mapi in VS 2005
environment:

Public objSession As New MSMAPI.MAPISession
Public objMessage As New MSMAPI.MAPIMessages

objSession.DownLoadMail = False
objSession.UserName = "MyUsername"
objSession.Password = "MyPassword"
objSession.SignOn()
objMessage.SessionID = objSession.SessionID
objMessage.Compose()

objMessage.RecipAddress = txtTo.Text
objMessage.Text = txtBody.Text
objMessage.Subject = txtSubject.Text

objMessage.Send(True) 'ShowDialog
MsgBox("Message sent successfully!")
objSession.SignOff()

I uninstalled Microsoft Outlook (comes along with msoffice), now my
default client is Outlook Express, I get this exception:

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
mailclient.exe

Can anybody help me out ?

Regards,
Sentiboy

Sep 6 '06 #1
3 4545
Why use an installed client when you can use the DotNet infrustructure,
which has it all built in?

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'SMTP EMAIL NOTES
'As condensed from: http://www.systemwebmail.com/default.aspx
'1. Have a reference set to the System.Web.dll.
'2. Have "Imports System.Web.Mail" statement at the top of your code.
'3. SmtpMail.SmtpServer must allow relaying for FROM email address or your
IP address,
' or you must use dotNET 1.1 or higher to authenticate.
'SAMPLE SETTINGS
'Dim emlEmail As New System.Web.Mail.MailMessage()
' NOTE: all email addresses can be like: "my********@my-domain.com" - OR -
Fully named like: """John Smith"" <my********@my-domain.com>"
' Also, multiple email addresses can be sent separated by semi-colon
character.
'emlEmail.To = "my********@my-domain.com"
'emlEmail.From = "my********@my-domain.com"
'emlEmail.Cc = "my********@my-domain.com" 'optional
'emlEmail.Bcc = "my********@my-domain.com" 'optional
'emlEmail.Subject = "SUBJECT_HERE"
'emlEmail.BodyFormat = MailFormat.Html
'emlEmail.Body = "BODY OF THE MESSAGE HERE"
'emlEmail.Headers.Add("Reply-To", "my********@my-domain.com")
'Attachments()
'Dim attachment As New System.Web.Mail.MailAttachment("C:\Foo.xls") 'create
the attachment
'emlEmail.Attachments.Add(attachment) 'add the attachment
'Authentication cannot be done using the .NET Framework 1.0. Must use 1.1 or
higher.
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1") 'basic authentication
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
"my_username_here") 'set your username here
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
"super_secret") 'set your password here
'SmtpMail.SmtpServer = "EMAIL_SERVER_DOMAIN" 'your real server goes here
'SmtpMail.Send(emlEmail)
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please note that the above example is for DotNet 1.x
http://www.systemwebmail.com/

To see more information for 2.x, see http://www.systemnetmail.com/

I have found these two sites very useful.

HTH.

Cheers!

~ Duane Phillips.

<se******@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
>I am using the following code for sending email through mapi in VS 2005
environment:

Public objSession As New MSMAPI.MAPISession
Public objMessage As New MSMAPI.MAPIMessages

objSession.DownLoadMail = False
objSession.UserName = "MyUsername"
objSession.Password = "MyPassword"
objSession.SignOn()
objMessage.SessionID = objSession.SessionID
objMessage.Compose()

objMessage.RecipAddress = txtTo.Text
objMessage.Text = txtBody.Text
objMessage.Subject = txtSubject.Text

objMessage.Send(True) 'ShowDialog
MsgBox("Message sent successfully!")
objSession.SignOff()

I uninstalled Microsoft Outlook (comes along with msoffice), now my
default client is Outlook Express, I get this exception:

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
mailclient.exe

Can anybody help me out ?

Regards,
Sentiboy

Sep 6 '06 #2
I just saw your previous similar-veined post, and realized my response may
not be what you are looking for, as you are actually trying to tie into the
Outlook messaging system. I have not dug that deeply into MAPI... I just
needed to be able to *send* email to our local email server from our
automated application. However, you may still find what you are looking for
at the sites I mentioned.

Cheers!

~ Duane Phillips.

"Duane Phillips" <du************@askme.askmewrote in message
news:Er******************************@giganews.com ...
Why use an installed client when you can use the DotNet infrustructure,
which has it all built in?

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'SMTP EMAIL NOTES
'As condensed from: http://www.systemwebmail.com/default.aspx
'1. Have a reference set to the System.Web.dll.
'2. Have "Imports System.Web.Mail" statement at the top of your code.
'3. SmtpMail.SmtpServer must allow relaying for FROM email address or your
IP address,
' or you must use dotNET 1.1 or higher to authenticate.
'SAMPLE SETTINGS
'Dim emlEmail As New System.Web.Mail.MailMessage()
' NOTE: all email addresses can be like: "my********@my-domain.com" - OR -
Fully named like: """John Smith"" <my********@my-domain.com>"
' Also, multiple email addresses can be sent separated by semi-colon
character.
'emlEmail.To = "my********@my-domain.com"
'emlEmail.From = "my********@my-domain.com"
'emlEmail.Cc = "my********@my-domain.com" 'optional
'emlEmail.Bcc = "my********@my-domain.com" 'optional
'emlEmail.Subject = "SUBJECT_HERE"
'emlEmail.BodyFormat = MailFormat.Html
'emlEmail.Body = "BODY OF THE MESSAGE HERE"
'emlEmail.Headers.Add("Reply-To", "my********@my-domain.com")
'Attachments()
'Dim attachment As New System.Web.Mail.MailAttachment("C:\Foo.xls")
'create the attachment
'emlEmail.Attachments.Add(attachment) 'add the attachment
'Authentication cannot be done using the .NET Framework 1.0. Must use 1.1
or higher.
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1") 'basic authentication
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
"my_username_here") 'set your username here
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
"super_secret") 'set your password here
'SmtpMail.SmtpServer = "EMAIL_SERVER_DOMAIN" 'your real server goes here
'SmtpMail.Send(emlEmail)
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please note that the above example is for DotNet 1.x
http://www.systemwebmail.com/

To see more information for 2.x, see http://www.systemnetmail.com/

I have found these two sites very useful.

HTH.

Cheers!

~ Duane Phillips.

<se******@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
>>I am using the following code for sending email through mapi in VS 2005
environment:

Public objSession As New MSMAPI.MAPISession
Public objMessage As New MSMAPI.MAPIMessages

objSession.DownLoadMail = False
objSession.UserName = "MyUsername"
objSession.Password = "MyPassword"
objSession.SignOn()
objMessage.SessionID = objSession.SessionID
objMessage.Compose()

objMessage.RecipAddress = txtTo.Text
objMessage.Text = txtBody.Text
objMessage.Subject = txtSubject.Text

objMessage.Send(True) 'ShowDialog
MsgBox("Message sent successfully!")
objSession.SignOff()

I uninstalled Microsoft Outlook (comes along with msoffice), now my
default client is Outlook Express, I get this exception:

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
mailclient.exe

Can anybody help me out ?

Regards,
Sentiboy


Sep 6 '06 #3
I need to do some checking with the latest stuff but the last I looked
around the first of the year, the elegant stuff in the framework wasn't
worth the effort to blow it up IN REAL WORLD APPLICATIONS!

My testing worked great in my office. The moment I took it to a real site -
my client's, not even the motely crew of real end users - it ran into
firewall problems.

I gave up and used VB 6 techniques!

It's on my list to revisit when I get time.

Elegance is all right. Working is better.

Regards,
Al
"Duane Phillips" <du************@askme.askmewrote in message
news:Er******************************@giganews.com ...
Why use an installed client when you can use the DotNet infrustructure,
which has it all built in?

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'SMTP EMAIL NOTES
'As condensed from: http://www.systemwebmail.com/default.aspx
'1. Have a reference set to the System.Web.dll.
'2. Have "Imports System.Web.Mail" statement at the top of your code.
'3. SmtpMail.SmtpServer must allow relaying for FROM email address or your
IP address,
' or you must use dotNET 1.1 or higher to authenticate.
'SAMPLE SETTINGS
'Dim emlEmail As New System.Web.Mail.MailMessage()
' NOTE: all email addresses can be like: "my********@my-domain.com" - OR -
Fully named like: """John Smith"" <my********@my-domain.com>"
' Also, multiple email addresses can be sent separated by semi-colon
character.
'emlEmail.To = "my********@my-domain.com"
'emlEmail.From = "my********@my-domain.com"
'emlEmail.Cc = "my********@my-domain.com" 'optional
'emlEmail.Bcc = "my********@my-domain.com" 'optional
'emlEmail.Subject = "SUBJECT_HERE"
'emlEmail.BodyFormat = MailFormat.Html
'emlEmail.Body = "BODY OF THE MESSAGE HERE"
'emlEmail.Headers.Add("Reply-To", "my********@my-domain.com")
'Attachments()
'Dim attachment As New System.Web.Mail.MailAttachment("C:\Foo.xls")
'create the attachment
'emlEmail.Attachments.Add(attachment) 'add the attachment
'Authentication cannot be done using the .NET Framework 1.0. Must use 1.1
or higher.
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1") 'basic authentication
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
"my_username_here") 'set your username here
'emlEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
"super_secret") 'set your password here
'SmtpMail.SmtpServer = "EMAIL_SERVER_DOMAIN" 'your real server goes here
'SmtpMail.Send(emlEmail)
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please note that the above example is for DotNet 1.x
http://www.systemwebmail.com/

To see more information for 2.x, see http://www.systemnetmail.com/

I have found these two sites very useful.

HTH.

Cheers!

~ Duane Phillips.

<se******@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
>>I am using the following code for sending email through mapi in VS 2005
environment:

Public objSession As New MSMAPI.MAPISession
Public objMessage As New MSMAPI.MAPIMessages

objSession.DownLoadMail = False
objSession.UserName = "MyUsername"
objSession.Password = "MyPassword"
objSession.SignOn()
objMessage.SessionID = objSession.SessionID
objMessage.Compose()

objMessage.RecipAddress = txtTo.Text
objMessage.Text = txtBody.Text
objMessage.Subject = txtSubject.Text

objMessage.Send(True) 'ShowDialog
MsgBox("Message sent successfully!")
objSession.SignOff()

I uninstalled Microsoft Outlook (comes along with msoffice), now my
default client is Outlook Express, I get this exception:

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
mailclient.exe

Can anybody help me out ?

Regards,
Sentiboy

Sep 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

40 posts views Thread by ian | last post: by
reply views Thread by David Burson | last post: by
2 posts views Thread by madfisher | last post: by
15 posts views Thread by cj | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.