Results 1 to 9 of 9

Thread: can send e-mails in VBA but not VB.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    can send e-mails in VBA but not VB.net

    I have code which sends e-mails in VBA and also in VB.net. My computers got upgraded to outlook 2013 so I updated my object library references. My VBA will send e-mails just fine but my VB.net stops working. What can I do to fix my VB.net?



    This will create the e-mail, fill it out correctly, display it, but when it gets to .send() it stops working.
    I can manually click send on the displayed e-mail and it sends just fine.




    Code:
    Public Sub e_mail()
            Dim olapp As Interop.Outlook.Application
            Dim olmail As Interop.Outlook.MailItem
    
    
            olapp = CreateObject("outlook.application")
            olmail = olapp.CreateItem(OlItemType.olMailItem)
            With olmail
                .BodyFormat = OlBodyFormat.olFormatHTML
                .To = email
                .Subject = drname & " MCR O2 documents needed."
                .HTMLBody = ("test")
                .SentOnBehalfOfName = "APRIA MCR 02"
                .Display()
                .Send()
            End With
        End Sub


    .send() throws this error:

    "The operation failed. The messaging interfaces have returned an unknown error. If the problem persists, restart Outlook. Cannot resolve recipient."

    If I manually click send on the e-mail it works just fine so it's not a size or recipient issue. Also e-mails are being sent just fine via VBA using this code:


    Code:
    Public Sub E_mail ()
    Set olApp = CreateObject("Outlook.Application")
    Set OlMail = olApp.CreateItem(olMailItem)
    
    
    
    
    With OlMail
       
        .to = "test_email@gmail.com"
        .SentOnBehalfOfName = "APRIA MCR 02"
        .Subject = "File ready for CO Medicaid claim cleaning "
        .send
    
    End With
    
    End Sub

  2. #2
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: can send e-mails in VBA but not VB.net

    Why don't you use a PHP mailer to send the email?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Re: can send e-mails in VBA but not VB.net

    Quote Originally Posted by Toph View Post
    Why don't you use a PHP mailer to send the email?
    I don't know how to. My company uses microsoft outlook.

  4. #4
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: can send e-mails in VBA but not VB.net

    My guess is the Outlook Security Warning is being triggered because it is an untrusted app. doing the sending. The linked article will explain what to do.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Re: can send e-mails in VBA but not VB.net

    Quote Originally Posted by Merrion View Post
    My guess is the Outlook Security Warning is being triggered because it is an untrusted app. doing the sending. The linked article will explain what to do.
    nope. I can send e-mails in VBA without any security issues.

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: can send e-mails in VBA but not VB.net

    Where is email(in the line: .To = email) declared, and what does it contain when run?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Re: can send e-mails in VBA but not VB.net

    Quote Originally Posted by Merrion View Post
    Where is email(in the line: .To = email) declared, and what does it contain when run?
    The e-mail address contains the e-mail variable from the data file that the e-mail is to be sent to. I know it's a valid e-mail because after the code creates the e-mail and makes it visible I can manually click send and the e-mail will send with no problems. It's declared as a public module level string variable.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Re: can send e-mails in VBA but not VB.net

    Quote Originally Posted by Merrion View Post
    My guess is the Outlook Security Warning is being triggered because it is an untrusted app. doing the sending. The linked article will explain what to do.
    I tried it and it still does not work.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Re: can send e-mails in VBA but not VB.net

    Anyone have an ideas about how I can fix this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width