Beny at work

Hello,

 

I need to create a function which send a mail. But when I execute my sub, I have a message warning. How can I send mail without this message

I need to send a mail to a user of my network, I use Exchange server.

thanks !

 

Ben

' Create an Outlook application.

Dim oApp As Outlook._Application

oApp = New Outlook.Application()

' Create a new MailItem.

Dim oMsg As Outlook._MailItem

oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)

oMsg.Subject = "Send Attachment Using OOM in Visual Basic .NET"

oMsg.Body = "Hello World" & vbCr & vbCr

' TODO: Replace with a valid e-mail address.

oMsg.To = "truc@muche.com"

' Add an attachment

' TODO: Replace with a valid attachment path.

Dim sSource As String = "C:\Temp\Hello.txt"

' TODO: Replace with attachment name

Dim sDisplayName As String = "Hello.txt"

Dim sBodyLen As String = oMsg.Body.Length

Dim oAttachs As Outlook.Attachments = oMsg.Attachments

Dim oAttach As Outlook.Attachment

oAttach = oAttachs.Add(sSource, , sBodyLen + 1, sDisplayName)

' Send

oMsg.Send()

' Clean up

oApp = Nothing

oMsg = Nothing

oAttach = Nothing

oAttachs = Nothing

 



Re: Visual Basic General Outlook - Send mail without a message warning

DMan1

It is a built in security feature of outlook....instead of using the outlook application to send email...use the system.net.mail namespace to send the mail




Re: Visual Basic General Outlook - Send mail without a message warning

Dustin_H

Here's how i do it, i don't get any popups though. Seems to be almost the same code.

Referenced is 'Microsoft Outlook 11.0 Object Library' (Microsoft.Office.Interop.Outlook.dll)

Imports Microsoft.Office.Interop.Outlook

Dim OO As Outlook.Application

Dim oMsg As Outlook._MailItem

If OO Is Nothing Then OO = New Outlook.Application

oMsg = OO.CreateItem(Outlook.OlItemType.olMailItem)

oMsg.Subject = "subjectˇ±

oMsg.Body = ˇ°bodyˇ±

oMsg.Attachments.Add(tFile)

oMsg.To = ˇ°to@to.comˇ±

oMsg.Send()

oMsg = Nothing

OO = Nothing