ACCESS 2007 - 在发生特定事件时使用 Outlook 自动发送和发送电子邮件

发布于 2024-11-25 21:22:40 字数 145 浏览 0 评论 0原文

我正在尝试在 Microsoft Access 2007 中创建一个应用程序。如何在特定事件发生时使用 Outlook 2007 以静默方式发送电子邮件,而无需任何用户交互。我应该如何处理这个问题。如果你能提供一些 VBA 那就太好了,但如果没有,你能指导我如何实现这一点吗?

I am trying to create an App in Microsoft Access 2007. How can I silently send an email out using Outlook 2007 upon a specific event without any user interaction. How should I approach this. If you can provide some VBA some it would be extremely nice, but if not, could you guide me in how to accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羁绊已千年 2024-12-02 21:22:40

我能够使用以下代码解决我的问题:

Public Sub SendEmail()

    Email_Bcc = "[email protected]"
    Email_Body = "Email body!!!!"
    Email_Subject = "Email Subject"

    On Error GoTo debugs

    Set Mail_Object = CreateObject("Outlook.Application")
    Set Mail_Single = Mail_Object.CreateItem(0)

    With Mail_Single
        .Subject = Email_Subject
        .To = Email_Send_To
        .cc = Email_Cc
        .BCC = Email_Bcc
        .Body = Email_Body
        .send
    End With

debugs:
    If Err.Description <> "" Then MsgBox Err.Description

End Sub

I was able to solve my problem with the following code:

Public Sub SendEmail()

    Email_Bcc = "[email protected]"
    Email_Body = "Email body!!!!"
    Email_Subject = "Email Subject"

    On Error GoTo debugs

    Set Mail_Object = CreateObject("Outlook.Application")
    Set Mail_Single = Mail_Object.CreateItem(0)

    With Mail_Single
        .Subject = Email_Subject
        .To = Email_Send_To
        .cc = Email_Cc
        .BCC = Email_Bcc
        .Body = Email_Body
        .send
    End With

debugs:
    If Err.Description <> "" Then MsgBox Err.Description

End Sub
小草泠泠 2024-12-02 21:22:40

首先在您想要发送电子邮件的事件中或在您希望事件调用的函数中声明几个变量。

Public Started As Boolean
Public oApp As Outlook.Application
Public oItem As Outlook.MailItem

接下来,打开或获取 Outlook(如果它正在运行)。

On Error Resume Next
'Get Outlook if it's running
Set oApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
     'Outlook wasn't running, start it from code
     Set oApp = CreateObject("Outlook.Application")
    Started = True
End If

现在,对您的电子邮件进行您需要做的事情。

 Set oItem = oApp.CreateItem(olMailItem)
 With oItem
    .To = "[email protected]"
    .Subject = "Your email, sirrah."
    .Body = "Please enjoy this complimentary email."
    'Send the email
    .Send
End With

最后,如果之前没有运行,请关闭 Outlook 并进行清理。

Set oItem = Nothing
If Started Then
    oApp.Quit
End If

First declare a couple variables in the event that you want to send the email, or in a function you'd like the event to call.

Public Started As Boolean
Public oApp As Outlook.Application
Public oItem As Outlook.MailItem

Next, open or get Outlook if it's running.

On Error Resume Next
'Get Outlook if it's running
Set oApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
     'Outlook wasn't running, start it from code
     Set oApp = CreateObject("Outlook.Application")
    Started = True
End If

Now, do what you've got to do with your email.

 Set oItem = oApp.CreateItem(olMailItem)
 With oItem
    .To = "[email protected]"
    .Subject = "Your email, sirrah."
    .Body = "Please enjoy this complimentary email."
    'Send the email
    .Send
End With

Finally, close outlook if it wasn't running before and clean up.

Set oItem = Nothing
If Started Then
    oApp.Quit
End If
忆梦 2024-12-02 21:22:40

您可以通过使用宏和“SendObject”操作来实现“无代码”。请务必填写所有必要的参数“收件人”、“主题”、“消息文本”,然后将“编辑消息”参数设置为“否”。

然后,您可以将此宏附加到您想要的任何事件,例如按钮的 OnClick 事件。

You can do this "code-free" by using a macro and the "SendObject" action. Be sure to complete all the necessary arguments To, Subject, Message Text, and then set the Edit Message argument to 'No'.

You can then attach this macro to any event you wish, such as the OnClick event of a button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文