Outlook object question in VB.NET



I am using VB.NET 2008 and in the COM Tab I add a reference to "Microsoft
Outlook 11.0 Object Library".
When I send an email, a window with the following message (and buttons Yes,
No, Help) always pops up on the screen:
"A program is trying to automatically send e-mail on your behalf. Do you
want to allow this ?
If this is unexpected, it may be a virus and you should choose "No"."

Why does that window pop up, and how can I make it not popup ?
Thank you very much.

Main program
Private oMail As New OutlookMail

sub myForm_Load(...)
end sub

Private Sub myForm_FormClosing(..)
oMail = Nothing
End Sub

Sub SendEmail(ByVal sMsg As String, ByVal sToEmail As String, ByVal sSubject
As String)
Dim swError As StreamWriter

If sToEmail <> "" Then
oMail.SendEmail(sToEmail, sSubject, sMsg)
End If

End Sub

Private Sub cmdEmail_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEmail.Click
SendEmail(txtLog.Text, txtEmails.Text, "my subject")
End Sub

Imports Outlook = Microsoft.Office.Interop.Outlook
Imports System
Public Class OutlookMail
Dim ns As Outlook.NameSpace
Public Function startOutlook()
'Return a reference to the MAPI layer
Dim ol As New Outlook.Application()

ns = ol.GetNamespace("MAPI")
ns.Logon(, , True, True)
End Function
Public Sub SendEmail(ByVal toVal As String, ByVal subjectVal As String,
ByVal bodyVal As String) ', ByVal sMailID As String)
Dim newMail As Outlook.MailItem
Dim fdMail As Outlook.MAPIFolder

fdMail =

'assign values to the newMail MailItem
newMail = fdMail.Items.Add(Outlook.OlItemType.olMailItem)
newMail.Subject = subjectVal
newMail.Body = bodyVal
newMail.To = toVal
newMail.SaveSentMessageFolder = fdMail
End Sub
End Class

Scott M.

Because you are accessing a mail client (Outlook), you will get Outlook's
built-in security. It comes up to prevent someone from writing a spam virus
that sends out gobs of email without the user knowing it.

I don't believe you can get around this since it is a security feature.
But, if you were to send mail (via code) directly from an SMTP server (like
MS Exchange) you wouldn't get that message.



Thank you for your reply.
The reason why I use Outlook is because with Outlook I can easily see all
the mails I sent in the "Sent" folder, but I can't do that easily with SMTP.

Scott M.

When sending mail from a server, you must look at the server logs to see
what's been sent.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question