Как мы можем войти в Outlook, используя Excel VBA?
Если у нас есть несколько имен пользователей и паролей на листе Excel, может ли код VBA войти в Outlook и отправить почту?
Sub Mail()
Dim myApp As Outlook.Application, mymail As Outlook.MailItem
Dim path, path1, path2, emp_name, subject, cc, body As String
Dim file, username, passwrod As String
Dim x, lastrow As Long
On Error GoTo ExitSub
lastrow = Sheets("Mail").Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
path1 = Cells(x, "A").Value
path2 = Cells(x, "B").Value
path = path1 & "\" & path2
emp_name = Cells(x, "C").Value
subject = Cells(x, "D").Value
body = Cells(x, "E").Value
cc = Cells(x, "G").Value
username = Cells(x, "H").Value
Password = Cells(x, "I").Value
Set myApp = New Outlook.Application
Set mymail = myApp.CreateItem(olMailItem)
mymail.To = Cells(x, "F").Value
If path <> "" Then
If (Cells(x, "F").Value) <> "" Then
With mymail
.Session.Logon username, Password, False, False
'.Display
.cc = cc
.subject = subject
.Attachments.Add path
.HTMLBody = "Hi " & emp_name & "," & "<br>" & "<br>" & body & "<br>" & .HTMLBody
.Display
.send
End With
Else
MsgBox ("Please Enter Mail ID")
Exit Sub
End If
Else
MsgBox ("Please check Path and File Name")
End If
Next x
Set myApp = Nothing
Set mymail = Nothing
ExitSub:
End Sub
Я ожидаю, что код войдет в Outlook с данными, указанными в листе Excel, и автоматически отправит почту.