Private Sub Command1_Click()
Call send_mail("郵件的標題")
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
.Subject = strSubject '主旨
.Body = strText '內容
.Save '存入寄件夾
.Send '出信件
End With
Set Mail = Nothing
OutLookMailto = True
Exit Function
Errh:
OutLookMailto = False
End Function
Private Sub send_mail(ByVal strSubject As String)
Dim colAddrs As New Collection
Dim colAttachs As New Collection
Dim strBody As String
Dim strText As String
Dim blnSendOK As Boolean
Dim SQL As String
colAddrs.Add "你的郵箱"
colAttachs.Add ""
strText = " 郵件內容 "
blnSendOK = OutLookMailto(OutLooks, strSubject, strText, colAddrs, colAttachs)
If blnSendOK = True Then
MsgBox "郵件發送成功!", vbInformation
Else
MsgBox "郵件發送未成功!", vbInformation
End If
'End
End Sub
Private Sub cmdAttachment_Click()
On Error Resume Next
With CommonDialog1
.DialogTitle = "Insert Attachment"
.Filter = "All Files (*.*)|*.*"
.ShowOpen
If Dir(.FileName) <> "" Then
txtAttachment.Text = .FileName
' 顯示 Attachment 的 Icon
oleAttachment.SourceDoc = .FileName
oleAttachment.CreateEmbed .FileName
Else
MsgBox "Attachment is not available.", vbCritical
End If
End With
End Sub
Private Sub cmdSend_Click()
' 開始 MAPI Session
MAPISession1.SignOn
' 當 MAPI Session 建立後,
' Session 所產生的 Handle 會存於 SessionID 屬性中
If MAPISession1.SessionID <> 0 Then