1

I m trying to send mail using the outlook , program is not showing any error but mail is not sent.

I have connected my gmail account to outlook , when manually tested it is outlook is working fine.

While configuring gmail id to outlook test mail came successfully.

Os Windows 10 , and outlook 2010 Below is the code and setting snapshot.

Please check and let me know what needs to be done ..

Imports Outlook = Microsoft.Office.Interop.Outlook  ' At the General Section of the Form  
Module Outlook_mail1
    Private Sub cmdMail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim oOutlook As New Outlook.Application
        Dim olNs As Outlook.NameSpace
        Dim oMail As Outlook.MailItem
        oOutlook = CreateObject("Outlook.Application")
        olNs = oOutlook.GetNamespace("MAPI")
        olNs.Logon()
        oMail = oOutlook.CreateItem(Outlook.OlItemType.olMailItem)
        oMail.Subject = "Subject of the mail"
        oMail.Body = "Text of the mail"
        oMail.To = "test.abc@test.com"
        oMail.ReadReceiptRequested = True
        oMail.Send()
    End Sub
End Module

enter image description here

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Aditi Patil
  • 67
  • 1
  • 11
  • Are you logged into outlook (even if it's closed) already on the computer? I took out the olNS portion and tied it to a button and it fired no issues. – Veegore Sep 17 '20 at 17:45
  • Looking at it more you're calling a MAPI namespace but then your account is set up as IMAP? – Veegore Sep 17 '20 at 17:46
  • I have related problem in python. Can help me with this please? https://stackoverflow.com/questions/71612698/python-mail-send-successful-but-outlook-email-not-delivered – The Great Mar 25 '22 at 05:52
  • Are you able to do the same operation manually in Outlook? Is your email sent out successfully in that case? – Eugene Astafiev Mar 27 '22 at 16:37
  • Does it make any difference if Outlook is running when your code is being executed? Does the message get sent if you click 'Send/ Receive"? – Dmitry Streblechenko Mar 27 '22 at 17:30

1 Answers1

0

First of all, I'd suggest adding a try/catch block to see whether the Send method gives any unpredictable results when Outlook is automated from an external application. Here is why...

The Outlook object model may trigger security prompts or throw errors when using unsafe methods and properties when Outlook is automated from other applications. See Protected Properties and Methods for the list the properties and methods in the Outlook object model that are protected by the Object Model Guard. If untrusted code performs a get on these properties or uses these methods, under default conditions for how Outlook is set up, it will invoke a security warning/issue.

To avoid security prompts/issues when dealing with OOM:

  • use a low-level API on which Outlook is based on and which doesn't trigger security prompts
  • use a third-party component which allows to turn off/on security warnings, see Outlook Security Manager for more information
  • install the latest version of any antivirus software
  • use group policy to change default settings

Finally, you may find the following articles helpful:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45