Solved

vb.net send email "a program is trying to automatically send e-mail one your behalf"

Posted on 2011-09-22
5
344 Views
Last Modified: 2012-08-13
I am using the below code to send an email to users when they have booked a holiday
Imports Microsoft.VisualBasic
Imports System.Net.Mail

Public Class sendemailtosuperusers
    Shared Function sendemail() As String
        ' 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 = "testing tom testing"
        oMsg.Body = "Hello World" & vbCr & vbCr

        ' TODO: Replace with a valid e-mail address.
        oMsg.To = "thomas.tyler@uk.experian.com"


        ' Send
        oMsg.Send()

        ' Clean up
        oApp = Nothing
        oMsg = Nothing
       
    End Function

End Class

Open in new window



but when i send the emil on each users computer i get the error "a program is trying to automatically send e-mail one your behalf"

is there any way to stop the error coming up via code?
0
Comment
Question by:runnerjp2005
5 Comments
 
LVL 6

Expert Comment

by:c1nmo
ID: 36580256
use the System.Net.Mail namespace instead of outlook automation
0
 

Author Comment

by:runnerjp2005
ID: 36580264
Dim message As String = "This is a test message" 

        Try
            Dim SendFrom As MailAddress = New MailAddress("ME@YOUREMIAL.com")
            Dim SendTo As MailAddress = New MailAddress("-")

            Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)

            MyMessage.Subject = "Sending an email through code"
            MyMessage.IsBodyHtml = True
            MyMessage.Body = message

            Dim emailClient As New SmtpClient("127.0.0.1")
            emailClient.Send(MyMessage)


        Catch ex As Exception

        End Try

Open in new window



i tired this and get no emails through!
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36580275
Use the SMTPClient in VB.Net, rather than instantiate Outlook.

      Dim oMailer As New SmtpClient '@@@ Mail object
      Dim oMailSender As New MailAddress(whatever)
      Dim oMailMessage As New MailMessage
      oMailMessage.IsBodyHtml = blnIsHTML

      strRecipient = whatever

      Try

        oMailMessage.From = oMailSender
        oMailMessage.To.Add(strRecipient)

        oMailMessage.Subject = whatever
        oMailMessage.Body = whatever


        '@@@ Build the e-mail message
        oMailer.Host = whatever
        oMailer.Send(oMailMessage)

      Catch ex As Exception
        Some error handling

      End Try
0
 
LVL 6

Expert Comment

by:c1nmo
ID: 36580319
Have you tried creating a NetworkCredential object and passing it to the SmtpClient.Credentials property?  SendTo address doesn't look right?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 36582153
You can suppress outlook messages by using this free addin

http://www.mapilab.com/outlook/security/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spam invasion 8 47
Tracking Bouncebacks in PHPMailer 3 38
Best secure sending email service 1 49
Web Form VB.Net  import CSV 4 26
MS outlook is a premier email client that enable you to send and receive the e-mails with various file formats of attachments such as document files, media file, and many others formats. There is some scenario occurs when a receiver of an e-mail mes…
Nearly six years ago I was hired by a company to be their senior server engineer. One of my first projects was to implement Exchange Server 2007 on a Windows Server 2008 Single Copy Cluster for high availability. That was the easy part; read on to l…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now