Dim OutLooks As New Outlook.ApplicationPrivate Sub Command1_Click() Call send_mail("Then IA CODE is going to run out!") End SubPublic 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 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 ' SQL = "select email_address from sftm40 where email_group = 'ME'" ' Set RS = DB.Execute(SQL) ' strBody = "您好:" & vbCrLf & " 您看到這封信時表示已成功傳送" 'While Not RS.EOF colAddrs.Add "[email protected]" '"[email protected]" 'Trim(RS.Fields("email_address")) ' RS.MoveNext 'Wend 'colAttachs.Add mFile colAttachs.Add "" strText = " The has already run out, please send the new range to Arima S/W team.&" _ & " Thank you very much! This mail for test program. " blnSendOK = OutLookMailto(OutLooks, strSubject, strText, colAddrs, colAttachs) If blnSendOK = True Then MsgBox "郵件發送成功!", vbInformation Else MsgBox "郵件發送未成功!", vbInformation End If 'End End Sub
Call send_mail("Then IA CODE is going to run out!")
End SubPublic 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 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
' SQL = "select email_address from sftm40 where email_group = 'ME'"
' Set RS = DB.Execute(SQL)
' strBody = "您好:" & vbCrLf & " 您看到這封信時表示已成功傳送"
'While Not RS.EOF
colAddrs.Add "[email protected]" '"[email protected]" 'Trim(RS.Fields("email_address"))
' RS.MoveNext
'Wend
'colAttachs.Add mFile
colAttachs.Add ""
strText = " The has already run out, please send the new range to Arima S/W team.&" _
& " Thank you very much! This mail for test program. "
blnSendOK = OutLookMailto(OutLooks, strSubject, strText, colAddrs, colAttachs)
If blnSendOK = True Then
MsgBox "郵件發送成功!", vbInformation
Else
MsgBox "郵件發送未成功!", vbInformation
End If
'End
End Sub