Need Help - VBA SMTP Mailing - Send all Listbox items

Mahantesh_Torgal

New Member
Joined
Sep 12, 2016
Messages
25
Hi Excel Teachers,

Can you please please help me with this?


I have VBA listbox which populates data for a given specific date range.
But i want to send as an email this Listbox items in table format using SMTP technique.


I tried but not getting the exact way.


Could you please help!! Below is the sample code


----------------------------------------------------
Private Sub CommandButton2_Click()
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant, i As Integer
Dim strbody As String, tlr As Integer, rng As Range, mess As Range
'rng = ""
tlr = ThisWorkbook.Sheets("temp").Range("A" & Rows.Count).End(xlUp).Row

'Range("A2:G26").Select
'Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
'Range("A2").Select

'------mailing Listitems

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.pfsweb.com"
.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With

strbody = "Hello All, " & vbNewLine & vbNewLine & _
"Below are the details of recovered Items : "


For i = 0 To UserForm20.ListBox1.ListCount - 1
With iMsg

Set .Configuration = iConf

'UserForm20.ListBox1.Selected(i) = True
.To = "mtoragall@pfsweb.com"
'.CC = ""
'.BCC = ""
.From = "easyasset@pfsweb.com"
.Subject = "EasyAsset Recovered Assets"
.Textbody = mess
'.Textbody = strbody & vbNewLine & vbNewLine & UserForm20.ListBox1.Column(1) & ", " & UserForm20.ListBox1.Column(2) & ", " & UserForm20.ListBox1.Column(3) & ", " & UserForm20.ListBox1.Column(4)
'Application.SendKeys "%s"
iMsg.Send
End With

Next i

End Sub

----------------------------------------------------

Regards,
Mahantesh
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top