Hi Team,
I have userform where i populate data in 4 columns using VBA Listbox (Columncount=4)
Now, i want to send these listbox items in an email using SMTP in tabular formati dont have installed EMail program on Server)
Please can anyone help!
--------------------------------------------------
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 : "
'mess = ""
Set mess = ThisWorkbook.Sheets("temp").Range("A1 :E" & tlr).Select
'For i = 1 To tlr
'For Each rng In mess
' rng.Value = rng.Value & mess
'Next rng
'Next i
'vbNewLine & vbNewLine & Me.List22.Column(1) & ", " & Me.List22.Column(2) & ", " & Me.List22.Column(3) & ", " & Me.List22.Column(4) & ", " & Me.List22.Column(5)
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
I have userform where i populate data in 4 columns using VBA Listbox (Columncount=4)
Now, i want to send these listbox items in an email using SMTP in tabular formati dont have installed EMail program on Server)
Please can anyone help!
--------------------------------------------------
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 : "
'mess = ""
Set mess = ThisWorkbook.Sheets("temp").Range("A1 :E" & tlr).Select
'For i = 1 To tlr
'For Each rng In mess
' rng.Value = rng.Value & mess
'Next rng
'Next i
'vbNewLine & vbNewLine & Me.List22.Column(1) & ", " & Me.List22.Column(2) & ", " & Me.List22.Column(3) & ", " & Me.List22.Column(4) & ", " & Me.List22.Column(5)
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