dneprcomp
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Sending an Outlook Mail Message Programmatically Create a sample text file named Customers.txt in the My Documents folder. Start Access, and create a database named Automation.mdb. Note The samples in this article use the Automation.mdb database that is included as a downloadable file with this article. Create a module and type the following line in the Declarations section if it is not already there: Option Explicit On the Tools menu, click References. In the References box, click to select the Microsoft Outlook 11.0 Object Library, and then click OK. Note If the Microsoft Outlook 11.0 Object Library does not appear in the Available References box, do the following: In Windows Control Panel, double-click Add or Remove Programs. In the list of installed programs, select Microsoft Office 2003, and then click Change. Microsoft Office 2003 Setup starts in maintenance mode. Click Reinstall or Repair, and then click Next. Click Detect and Repair errors in my Office installation, and then click Install. Click OK to close the References dialog box. Type or paste the following VBA procedure in the new module: Код: Sub sbSendMessage(Optional AttachmentPath) Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Outlook.Recipient Dim objOutlookAttach As Outlook.Attachment On Error GoTo ErrorMsgs ' Create the Outlook session. Set objOutlook = CreateObject("Outlook.Application") ' Create the message. Set objOutlookMsg = objOutlook.CreateItem(olMailItem) With objOutlookMsg ' Add the To recipient(s) to the message. Substitute ' your names here. Set objOutlookRecip = .Recipients.Add("Nancy Davolio") objOutlookRecip.Type = olTo ' Add the CC recipient(s) to the message. Set objOutlookRecip = .Recipients.Add("Andrew Fuller") objOutlookRecip.Type = olCC ' Set the Subject, Body, and Importance of the message. .Subject = "This is an Automation test with Microsoft Outlook" .Body = "Last test." & vbCrLf & vbCrLf .Importance = olImportanceHigh 'High importance ' Add attachments to the message. If Not IsMissing(AttachmentPath) Then Set objOutlookAttach = .Attachments.Add(AttachmentPath) End If ' Resolve each Recipient's name. For Each objOutlookRecip In .Recipients If Not objOutlookRecip.Resolve Then objOutlookMsg.Display End If End If Next .Send End With Set objOutlookMsg = Nothing Set objOutlook = Nothing Set objOutlookRecip = Nothing Set objOutlookAttach = Nothing ErrorMsgs: If Err.Number = "287" Then MsgBox "You clicked No to the Outlook security warning. " & _ "Rerun the procedure and click Yes to access e-mail" & _ "addresses to send your message. For more information, & _ "see the document at http://www.microsoft.com/office" & _ "/previous/outlook/downloads/security.asp. " " Else Msgbox Err.Number, Err.Description End If End Sub | Note Because of the Outlook E-Mail Security Update, when you run the following procedures, you will be prompted several times for permission to access your e-mail addresses and one prompt to send your message (see the following screen shots). This is expected behavior. For more information, see Security Features for Outlook 2002 and Previous Versions. Prompt 1. Prompt to access e-mail addresses Prompt 2. Prompt to send e-mail message To test this procedure, type the following line in the Immediate window in the Visual Basic Editor, and then press ENTER: sbSendMessage "C:\Documents and Settings\UserName\My Documents\Customers.txt" | Всего записей: 3920 | Зарегистр. 31-03-2002 | Отправлено: 00:17 01-04-2006 | Исправлено: dneprcomp, 00:21 01-04-2006 |
|