wuhoatu
Senior Member
Mình sử dụng đoạn code VBA dưới đây để tự gửi email (theo mẫu soạn sẵn trong file msg) kèm kết quả tính toán từ file excel. Vấn đề là chỉ gửi được từ email account mặc định của outlook. Nếu gửi bằng 1 tài khoản khác (cũng đã khai báo trong outlook) bằng SendUsingAccount thì báo lỗi "This message was created automatically by mail delivery software."
Các cao thủ vba/excel cho mình xin chút comment. Many THX
Các cao thủ vba/excel cho mình xin chút comment. Many THX
Code:
Sub SendMail()
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olAccount As Outlook.Account
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItemFromTemplate("full_path_file_name.msg")
Set olAccount = olApp.Session.Accounts("email_sender_here")
With olMail
.To = "[email protected]"
.SendUsingAccount = olAccount
.Send
End With
Set olMail = Nothing
Set olApp = Nothing
Set olAccount = Nothing
End Sub