Cho mình hỏi, mình ko dùng code xuất file PDF trực tiếp, nhưng mình có 1 list các file PDF có sẵn, mình viết code để gửi mail hàng loạt (mỗi mail gán 1 att khác nhau cho 1 người). Nhưng bị báo lỗi như sau:
Mặc dù đã kiểm tra path và filename trùng hết với file PDF rồi. Và khi kick vào Thisworkbook.path nó vẫn hiện ra đường dẫn đến các file mình đã lưu. Nhưng không hiểu sao cứ lỗi hoài, mong được admin giải đáp ạ.
Chào bạn bạn có thể đẩy file đính kèm lên được không?
Chào bạn bạn cho gitiho xin quyền truy cập nhé.
Mình gửi lại nhé
Chào bạn bạn phải biết được đường đẫn bạn nhé. hoặc bạn có thể dùng code sau:
lưu ý nhớ vào reapps"> https://myaccount.google.com/le tích gửi gmail kém an toàn nhé.
phần sAttachment bạn lấy đường dẫn vào nhé.
Sub guiemail()
Call Send_Email_With_Gmail("mailgui", "mailnhan", "Gitiho", "alo12345")
End Sub
' Cú pháp gui:Send_Email_With_Gmail(Emailgui, email nhan, subject, body, file dinh kem)
Option Explicit
Sub Send_Email_With_Gmail(sMailFrom, sMailTo, sSubject, sBody, Optional sAttachment = Null)
Dim newMail As Object
Dim mailConfiguration As Object
Dim msConfigURL As String
Dim fields As Variant
On Error GoTo errHandle
' reapps"> https://myaccount.google.com/le" style="max-width: 100%;"> https://myaccount.google.com/le...
Set newMail = CreateObject("CDO.Message")
Set mailConfiguration = CreateObject("CDO.Configuration")
mailConfiguration.Load -1
Set fields = mailConfiguration.fields
With newMail
.bodypart.Charset = "utf-8" ' h? tr? UTF-8 - ti?ng Vi?t
.Subject = sSubject
.From = sMailFrom
.To = sMailTo
.CC = ""
.BCC = ""
.TextBody = sBody
If (sAttachmet <> Null) Then
.AddAttachment sAttachment
End If
End With
msConfigURL = " http://schemas.microsoft.com/cdo/configu"
With fields
.Item(msConfigURL & "/smtpusessl") = True
.Item(msConfigURL & "/smtpauthenticate") = 1
.Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
.Item(msConfigURL & "/smtpserverport") = 465
.Item(msConfigURL & "/sendusing") = 2
.Item(msConfigURL & "/sendusername") = Sheet1.Range("A1").Value ' <- Thay d?a ch? email c?a b?n vào dây
.Item(msConfigURL & "/sendpassword") = Sheet1.Range("A2").Value ' <- Thay m?t kh?u email c?a b?n vào dây
.Update
End With
newMail.Configuration = mailConfiguration
newMail.Send
Debug.Print "E-Mail has been sent to " & sMailTo, vbInformation
exit_line:
'// Xoá object, ti?t ki?m b? nh?
Set newMail = Nothing
Set mailConfiguration = Nothing
Exit Sub
errHandle:
MsgBox "Error: " & Err.Description, vbInformation
End Sub
bạn có thể dùng code sau khong gửi gmail qua oulookup
Cảm ơn admin, để mình thử code kia. Nhưng file của mình lỗi gì vậy admin nhỉ?
Code của bạn dang lỗi thư viện này olMailItem bạn có thể xem cách gửi email qua oulookup tại đây