Dear,
normally i am able to send mail using gmail with example text by typing in body field.
but i want to send Range(A8:D17) as message body.
first i defined body1 as variable range, then i set body1 as value of my required range
in body of message i used variable 'body1' but it is giving error "run-time error '13' , Type mismached "
pls find the code as below...i which i am using and found by goggling...
'If you have a GMail account then you can try this example to use the GMail smtp server
'The example will send a small text message
'You must change four code lines before you can test the code
'.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Full GMail mail address"
'.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "GMail password"
'Use your own mail address to test the code in this line
'.To = "Mail address receiver"
'Change YourName to the From name you want to use
'.From = """YourName"" <Reply@something.nl>"
'If you get this error : The transport failed to connect to the server
'then try to change the SMTP port from 25 to 465
Sub CDO_Mail_Small_Text_2()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant
Dim body1 As Range
Set body1 = Sheets("Levels").Range("A8:D17").SpecialCells(xlCellTypeVisible)
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/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "fun4swamy@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "my id's pw"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Update
End With
strbody = "Pivot levels for " & Format$(Date, "mm-dd-yyyy") & vbNewLine & vbNewLine & _
vbNewLine & vbNewLine & _
body1
With iMsg
Set .Configuration = iConf
.To = "vsoma@ymail.com"
.CC = ""
.BCC = ""
' Note: The reply address is not working if you use this Gmail example
' It will use your Gmail address automatic. But you can add this line
' to change the reply address .ReplyTo = "Reply@something.nl"
.From = "fun4swamy@gmail.com"
.Subject = "Quadra Pivot Levels to trade on " & Format$(Date, "mm-dd-yyyy")
.TextBody = strbody
.Send
End With
End Sub
pls suggest me where i need to change in ordger to send mail using range as body
Bookmarks