firstly go to VBA=>Tools=>Reference then click mark box Microsoft CDO for Windows 2000 Library
then try this code for yahoo and gmail configuration
code:
Public Function SendEmailUsingOther(strSendTo As String, strSubject As String, MailType As String, fld As String, Optional tempfile, Optional attch1, Optional attch2, Optional attch3)
MailSent = False
Dim NewMail As CDO.Message
Set NewMail = New CDO.Message
‘Set myMail = CreateObject(“CDO.Message”)
‘Enable SSL Authentication
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = True
‘Make SMTP authentication Enabled=true (1)
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = 1
‘Set the SMTP server and port Details
‘To get these details you can get on Settings Page of your Gmail Account
Select Case MailType
Case “yahoo”
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 465
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “smtp.mail.yahoo.com”
Case “gmail”
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 465
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “smtp.gmail.com”
End Select
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
‘Set your credentials of your Gmail Account
SenderEmail = InputBox(“Please enter your email address”)
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/sendusername”) = SenderEmail
NewMail.Configuration.Fields.Item _
(“
http://schemas.microsoft.com/cdo/configuration/sendpassword”) = InputBox(“Please enter your password”)
‘Update the configuration fields
NewMail.Configuration.Fields.Update
NewMail.Configuration.Fields.Item(“
http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = “true”
‘Set All Email Properties
‘##########################”"
‘Open the HTML file using the FilesystemObject into a TextStream object
Set FSObj = New Scripting.FileSystemObject
Set TStream = FSObj.OpenTextFile(fld, ForReading)
‘Now set the HTMLBody property of the message to the text contained in the TextStream object
strHTML = TStream.ReadAll
‘################################
With NewMail
.Subject = [G2].Value
.From = SenderEmail
.to = [A2].Value
.CC = [B2].Value
.BCC = [C2].Value
.TextBody = vbCrLf & "Hi," _
& vbCrLf & vbCrLf & [i3].Value & "." _
& vbCrLf & [i4].Value _
& vbCrLf & vbCrLf & "Regards," _
& vbCrLf & "Amol"
.HTMLBody = strHTML
.Attachments.Add Destwb.FullName
'You can add other files also like this
.Attachments.Add ([E2].Value)
.Display 'or use .Send
If tempfile “” Then
.AddAttachment tempfile
End If
If Trim(attch1) “” Then
.AddAttachment attch1
End If
If Trim(attch2) “” Then
.AddAttachment attch2
End If
If Trim(attch3) “” Then
.AddAttachment attch3
End If
End With
‘MsgBox (strHTML)
NewMail.Send
‘MsgBox (“Mail has been Sent”)
MailSent = True
pbsend:
If MailSent = False Then
MsgBox (“Due to an issue (password, email address,attachments…), the email hasn’t been sent”)
End If
‘Set the NewMail Variable to Nothing
Set NewMail = Nothing
End Function