Dim EmailApp As Outlook.Application
Dim Source As String
Set EmailApp = New Outlook.Application
Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)
EmailItem.To = "Hi@gmail.com"
EmailItem.CC = "hello@gmail.com"
EmailItem.BCC = "hhhh@gmail.com"
EmailItem.Subject = "Test Email From Excel VBA"
EmailItem.HTMLBody = "Hi," & vbNewLine & vbNewLine & "This is my first email from Excel" & _
vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"VBA Coder"
Source = ThisWorkbook.FullName
EmailItem.Attachments.Add Source
EmailItem.Send
End Sub
Option Explicit
Sub Sendmail()
Dim Mail As New Message, Config As Configuration
Dim subject As String, mailbody As String, i As Long, lr As Long
ThisWorkbook.Sheets("Sheet1").Activate
subject = Range("H2").Value
lr = Range("C" & Rows.Count).End(xlUp).Row
For i = 2 To lr
Set Config = Mail.Configuration
Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp.gmail.com"
Config(cdoSMTPServerPort) = 465
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "Your GMail Account Name Here"
Config(cdoSendPassword) = "Your GMail Account Password Here"
Config.Fields.Update
mailbody = "Dear " & Range("c" & i).Value & "," & Range("h3").Value & vbCrLf & vbCrLf
Mail.To = Range("D" & i).Value
Mail.cc = Range("E" & i).Value
Mail.From = Config(cdoSendUserName)
Mail.subject = Range("c" & i).Value & " " & subject
Mail.HTMLBody = mailbody
'Mail.AddAttachment Range("F" & i).Value
On Error Resume Next
Mail.Send
On Error GoTo 0
Set Config = Nothing
Set Mail = Nothing
Next i
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "There was an error"
Else
MsgBox "Your email has been send", vbInformation, "Sent"
End If
End Sub
thanks for the solution, Logit!You can use the built-in Mail app if you want to send mail in Windows 10 without Outlook. However, remember that the code you wrote for Outlook may need to be modified to work with the Mail app. The API and syntax may differ between the two platforms. I recommend looking at the documentation and resources related to the Mail app for Windows 10 to see what changes need to be made to the code. You may need to adapt the VBA code or switch to another programming language depending on the capabilities of the Mail app. To get full access to all the operating system's features, buying cheap windows keys is recommended. Good luck, and I hope you find a solution.