1

I am creating a tool that will automatically dispatch emails out.

I have started to build it using very simple code as below:

Set outlookobj = New Outlook.Application
Set mitem = outlookobj.CreateItem(olMailItem)

With mitem
.To = "A_Valid_Email@email.com"
.Subject = "TEST"
.Body = "test"
.Display
.Send

End With
End Sub

However the company I work for seem to have locked down .send. The email will create fine but will not send. Can anyone think of a way around this? I have considered using .sendkeys "^{ENTER}" however I know they are not a good way to doing things.

Thank you in advance Matt

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Matthew Hopkins
  • 25
  • 1
  • 3
  • 8

2 Answers2

0

If you're okay with not using Outlook, you can use CDO to send emails. I'm not sure if this will get around your security issue, but it might be worth a try. Here is an example.

Sub CDO_Mail_Small_Text(ByVal RecipientList As String, ByVal From As String, _
        ByVal Subject As String, ByVal Body As String, ByVal Attachment As String, _
        ByVal cc As String)
    Dim iMsg As Message
    Dim iConf As Configuration
    Dim strbody As String
    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
                       = "webmail.zimmer.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With

    With iMsg
        Set .Configuration = iConf
        .To = RecipientList
        .cc = cc
        .From = From
        .Subject = Subject
        .HTMLBody = Body
    End With

    If Attachment <> "" Then
        iMsg.AddAttachment Attachment
    End If

    iMsg.Send

End Sub

By the way, this has the additional advantage of letting you spoof the sender and make it appear as though it came from someone else. I don't know if that's handy or not, but just FYI.

Hambone
  • 15,600
  • 8
  • 46
  • 69
  • Hi Hambone, I looked into doing something like this, however i am must use Outlook for security purposes. Im beginning to see a loop here. Thanks for the response though - Matt – Matthew Hopkins Jan 11 '16 at 15:06
  • I hear ya... keep it in mind if the powers that be get desperate. Good luck. – Hambone Jan 11 '16 at 15:10
0

I'm referring to this thread: Excel VBA sending mail using Outlook - Send method fails where the solution was the following:

"Change .Send to .Display and put SendKeys "^{ENTER}" before the With mitem line."

You can at least try it, maybe it works for you as well. :)

Community
  • 1
  • 1
Kathara
  • 1,226
  • 1
  • 12
  • 36
  • Hi, I've played with sendkeys earlier today, it either works fine or highlights the from column, i cant see any logical reason which one it goes for. I've been trying to find a way to make vba find the word "Send" and click. No joy so far – Matthew Hopkins Jan 11 '16 at 15:47
  • Worth a try. I hope you'll find a solution. Good luck – Kathara Jan 11 '16 at 15:56