send email via outlook

When attempting to send a email from my application via outlook with the following code. I am always prompted to supply a username and password for the account, even thought the dialog box has them in and i have checked save password. is there any way off coding this not to happen ?

Imports Microsoft.VisualBasic

Imports System.net.Mail

Imports Microsoft.Office.Interop

PublicSharedSub EmailwithOutlook()

Dim oOAppAs Outlook.Application

Dim oOMailAs Outlook.MailItem

oOApp = CreateObject("Outlook.Application")

oOMail = oOApp.CreateItem(Outlook.OlItemType.olMailItem)

With oOMail

.To ="username@hotmail.com"

.Subject ="email subject " &Date.Now

.Body ="email message"

'.Attachments.Add("\\server\drive\folder\filename", olByValue, 1)

.Send()

EndWith

EndSub

[2080 byte] By [Bigmo] at [2008-2-8]
# 1

Is there a reason you coding specifically to Outlook and not simply using the default email client.

Check out this post.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=670724&SiteID=1

or to send using local or remote email servers and mail directly from your app view this -

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim msg As New System.Net.Mail.MailMessage("moi@mydomain.com", "you@yourdomain.ie")

' Set message attributes

msg.Subject = " Having a good day?"

msg.Body = "Better than depending on a specific app!"

msg.Priority = Net.Mail.MailPriority.High

msg.IsBodyHtml = False

Dim client As New System.Net.Mail.SmtpClient("Remotemailserver")

Dim creds As New System.Net.NetworkCredential("RemoteUserName", "RemotePassword")

client.Credentials = creds

' or for other authentication with local server

'client.Credentials= system.Net.CredentialCache.DefaultCredentials

'client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials

' Async send

Dim MailToken As String = My.User.Name

AddHandler client.SendCompleted, AddressOf Me.MailSendComplete

client.SendAsync(msg, MailToken)

End Sub

' Async callback handler

Private Sub MailSendComplete(ByVal Sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)

If Not Nothing Is e.Error Then

MessageBox.Show("Mail Sending error: " & e.Error.InnerException.ToString)

End If

End Sub

Rgds,

Martin.

mokeefe at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Interop and Upgrade...
# 2

I seem to recall that there was a change in outlook which cause this dialog to appear every time you used the object model. There didnt appear a nice way round it - ended up sending emails directly using the .net classes to send to smtp server without using outlook.

spotty at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Interop and Upgrade...