Option ExplicitDim OUTLOOKS As New Outlook.Application Public Function OutLookMailto(OUTLOOKS As Outlook.Application, _ ByVal strSubject As String, _ ByVal strText As String, colAddrList As Collection, _ colAttachments As Collection) As Boolean Dim Mail As MailItem Dim strTemp Set Mail = OUTLOOKS.CreateItem(olMailItem) '設定要一個新的Mail Item With Mail For Each strTemp In colAddrList .Recipients.Add strTemp '新增收件人 Next ' For Each strTemp In colAttachments ' .Attachments.Add strTemp 'Attach的File ' Next .Subject = strSubject '主旨 .Body = strText '內容 .Save '存入寄件夾 .Send '出信件 End With Set Mail = Nothing OutLookMailto = True Exit Function Errh: OutLookMailto = False End FunctionPrivate Sub Command1_Click() Call send_mail("請維護客戶料號!") End Sub Private Sub send_mail(ByVal strSubject As String) Set OUTLOOKS = New Outlook.Application Dim colAddrs As New Collection Dim colAttachs As New Collection Dim strBody As String Dim strText As String Dim blnSendOK As Boolean colAddrs.Add "[email protected]" colAddrs.Add "[email protected]" colAttachs.Add "" strText = "內容" blnSendOK = OutLookMailto(OUTLOOKS, strSubject, strText, colAddrs, colAttachs) End End Sub
Public Function OutLookMailto(OUTLOOKS As Outlook.Application, _
ByVal strSubject As String, _
ByVal strText As String, colAddrList As Collection, _
colAttachments As Collection) As Boolean
Dim Mail As MailItem
Dim strTemp
Set Mail = OUTLOOKS.CreateItem(olMailItem) '設定要一個新的Mail Item
With Mail
For Each strTemp In colAddrList
.Recipients.Add strTemp '新增收件人
Next
' For Each strTemp In colAttachments
' .Attachments.Add strTemp 'Attach的File
' Next
.Subject = strSubject '主旨
.Body = strText '內容
.Save '存入寄件夾
.Send '出信件
End With
Set Mail = Nothing
OutLookMailto = True
Exit Function
Errh:
OutLookMailto = False
End FunctionPrivate Sub Command1_Click()
Call send_mail("請維護客戶料號!")
End Sub
Private Sub send_mail(ByVal strSubject As String)
Set OUTLOOKS = New Outlook.Application
Dim colAddrs As New Collection
Dim colAttachs As New Collection
Dim strBody As String
Dim strText As String
Dim blnSendOK As Boolean
colAddrs.Add "[email protected]"
colAddrs.Add "[email protected]"
colAttachs.Add ""
strText = "內容"
blnSendOK = OutLookMailto(OUTLOOKS, strSubject, strText, colAddrs, colAttachs)
End
End Sub
我說的是WinSock發送郵件,而且是網頁效果郵件,
不是用VBA的方法,我貼的圖片會直接在郵件的內容中直接顯示出來,
而不是當成附件,敬請大蝦指點迷津.