Microsoft Excel - How can I send rows that match a value in the body of an email (CDO, like Gmail...)?

Asked By Antonio Santos on 12-Sep-17 06:31 PM
How can I have rows that match a criteria within column O sent in the body of an email configured on CDO - Gmail basis?
Here is the code put together so far:

Sub CDO_Mail_Small_Text()
Dim iMsg As Object
Dim iConf As Object
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") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
.Update 'Let CDO know we have change the default configuration for this message
End With



strbody = "Atenção! Esses itens chegaram no estoque mínimo!" & " Favor verificar imediatamente e confirmar a necessidade de compra!" & vbNewLine & _
"" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"


With iMsg
Set .Configuration = iConf
.To = ""
.CC = ""
.BCC = ""
.From = """Estoque"" <>"
.Subject = "Atenção! Estoque de Insumos e MP baixo!"
.TextBody = strbody
.Send
End With


End Sub

Thank you!!!