Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-22
5
Medium Priority
?
372 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 2000 total points
ID: 36582153
You can suppress outlook messages by using this free addin

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

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
Phishing emails are a popular malware delivery vehicle for attack.  While there are many ways for an attacker to increase the chances of success for their phishing emails, one of the most effective methods involves spoofing the message to appear to …
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Suggested Courses

972 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