Office中国论坛/Access中国论坛

标题: [求助]请问如何向查询结果里所有有Email地址的客户发Email [打印本页]

作者: weiw3    时间: 2006-6-15 04:10
标题: [求助]请问如何向查询结果里所有有Email地址的客户发Email
请问一下大家,我要向我的客户数据库里有Email地址的客户发送资料。请问这样的功能如何实现?

例如说,我的客户数据库里有工程部门,市场部门等等。当我利用查询选出所有工程部门的记录,并且向他们发送Email。我能不能建一个按钮,将我查询到的所有结果里的Email地址传输到Outlook里,新建一封邮件,实现群发呢?还有一个小要求就是收件人不能看到我还将这个邮件发送给了其他的客户,也就是不显示收件人地址。

多谢了!
作者: weiw3    时间: 2006-6-15 07:10
有人知道吗?顶一下!
作者: swo    时间: 2006-6-15 09:01
这个不会,但我想到一个就是直接生成邮件地址的文本,然后复制过去。

还有就是参考一下网页制作里的mailto看有没有帮助,我没有试过,只是想到了这些
作者: fan0217    时间: 2006-6-15 09:46
参考:http://www.office-cn.net/forum.php?mod=viewthread&tid=37148&replyID=&skin=1
作者: Benjamin_luk    时间: 2006-6-15 17:51
以下是微软网上的标准代码, 供你参考:

'Msoutl8.olb     
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
          Dim objOutlook As Outlook.Application
          Dim objOutlookMsg As Outlook.MailItem
          Dim objOutlookRecip As Outlook.Recipient
          Dim objOutlookAttach As Outlook.Attachment
          ' 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.
              Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
              objOutlookRecip.Type = olTo
              ' Add the CC recipient(s) to the message.
              Set objOutlookRecip = .Recipients.Add("Michael Suyama")
              objOutlookRecip.Type = olCC
             ' Add the BCC recipient(s) to the message.
              Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
              objOutlookRecip.Type = olBCC
             ' Set the Subject, Body, and Importance of the message.
             .Subject = "This is an Automation test with Microsoft Outlook"
             .Body = "This is the body of the message." &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
                 objOutlookRecip.Resolve
             Next
             ' Should we display the message before sending?
             If DisplayMsg Then
                 .Display
             Else
                 .Save
                 .Send
             End If
          End With
          Set objOutlook = Nothing
      End Sub

如果不想让别人看到MAIL发给了谁,请选BCC.


作者: weiw3    时间: 2006-6-16 01:34
以下是引用Benjamin_luk在2006-6-15 9:51:00的发言:


以下是微软网上的标准代码, 供你参考:

'Msoutl8.olb     
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
          Dim objOutlook As Outlook.Application
          Dim objOutlookMsg As Outlook.MailItem
          Dim objOutlookRecip As Outlook.Recipient
          Dim objOutlookAttach As Outlook.Attachment
          ' 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.
              Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
              objOutlookRecip.Type = olTo
              ' Add the CC recipient(s) to the message.
              Set objOutlookRecip = .Recipients.Add("Michael Suyama")
              objOutlookRecip.Type = olCC
             ' Add the BCC recipient(s) to the message.
              Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
              objOutlookRecip.Type = olBCC
             ' Set the Subject, Body, and Importance of the message.
             .Subject = "This is an Automation test with Microsoft Outlook"
             .Body = "This is the body of the message." &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
                 objOutlookRecip.Resolve
             Next
             ' Should we display the message before sending?
             If DisplayMsg Then
                 .Display
             Else
                 .Save
                 .Send
             End If
          End With
          Set objOutlook = Nothing
      End Sub

如果不想让别人看到MAIL发给了谁,请选BCC.

请问这个代码怎么用啊?我完全是菜鸟一个,刚刚接触Access。
作者: fan0217    时间: 2006-6-16 01:43
4楼不是由现成的例子吗?
作者: weiw3    时间: 2006-6-16 01:55
以下是引用fan0217在2006-6-15 1:46:00的发言:


参考:http://www.office-cn.net/forum.php?mod=viewthread&tid=37148&replyID=&skin=1

我下载了,但是用不了,提示



[attach]18513[/attach]

点了确定以后又出现这个提示




[attach]18514[/attach]



然后出现使用界面,但是点任何的按钮都会弹出以上的提示。不过我觉得这个软件基本上能实现我要的功能。不知道楼上的能不能教教我怎么将这个程序移植到我的数据库来?多谢了!

作者: fan0217    时间: 2006-6-16 01:57
你检查是否有丢失的引用。

可查看其中的代码,里面有中文注释的。



对了,你的Office是什么版本的。

[此贴子已经被作者于2006-6-15 17:58:47编辑过]


作者: weiw3    时间: 2006-6-16 02:05
版主在啊!

哦,我试试看。我的office是2003的,英文版。

是不是把5楼的原代码贴到我原来的那些代码里,然后改一些相应的引用啊什么的就行了?
作者: weiw3    时间: 2006-6-16 02:14
郁闷啊!我的Access看不到中文的。
作者: weiw3    时间: 2006-6-16 05:56
我按照4楼提供的语句新建了一个Module,可以运行,但是就是不知道怎么把收信人的那个选项改成我的数据库里搜索结果的email地址,进行群发。控制收信人的那个语句是

' Add the To recipient(s) to the message.
     Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
      objOutlookRecip.Type = olBCC

那个括号里的"Nancy Davolio"一定要输入的,不能空。但是我想把我的查询结果里的Email地址输出到这里。

还有就是标题和内容,我怎么样才能使用指定的一个模板样式呢?语句是

' Set the Subject, Body, and Importance of the message.
      .Subject = "Test"
      .Body = "Testing." & vbCrLf & vbCrLf

在这里这个.Subject=和.Body=后面应该怎么写,或用什么别的语句?

最后一个问题就是,如果上面的这些功能都实现以后,我可以在我的查询表格里建一个键,直接启动这个Module吗?

多谢了!!!

[此贴子已经被作者于2006-6-15 21:59:09编辑过]


作者: fan0217    时间: 2006-6-16 06:13
那需要涉及到ADO,通过建立记录集,然后循环发邮件就可以了 。

下面是通过Outlook发送邮件,需要对Outlook做正确的配置才能发送。

Dim olApp As Outlook.Application
Dim myMail As MailItem

    Set olApp = Outlook.Application
    Set myMail = olApp.CreateItem(olMailItem)
    With myMail
        .Recipients.Add ("收件人地址")
        .CC ="抄送地址"
        .BCC = "秘密抄送地址"
        .Subject = "主题"
        .Body = "正文"
        .Attachments.Add ("附件地址")
        .Save
        .Send
    End With

将上面引号中的内容更换成你的内容就可以了。


[此贴子已经被作者于2006-6-15 22:36:41编辑过]


作者: weiw3    时间: 2006-6-17 00:15
版主,记录集怎么建啊?是不是把我查询结果里的Email地址生成一个文件啊?

还是你在上面说的把引号中的内容换成我的内容,我的内容是指在我的数据库里查询结果里的Email地址位置是吗?比如说,我的查询结果是在 Query.Product Query的Email字段里,那我在引号里就填 Query_Product Query_Email,对吗?

谢了!

[此贴子已经被作者于2006-6-16 16:28:47编辑过]


作者: fan0217    时间: 2006-6-17 04:16
看来你需要对ADO有一些了解才行啊,以下是建立记录集的典型代码

Dim conn As New ADODB.Connection
Dim rsTemp As New Recordset
Dim strSQL As String


   Set conn = CurrentProject.Connection


   strSQL = "SELECT * FROM 表1;"
   rsTemp.Open strSQL, conn, adOpenKeyset, adLockOptimistic


通过上面用ADO建立的记录集rsTemp后,就可以使用rsTemp("字段名称")获得表1中的记录了。

在通过循环记录集中的记录就可以实现群发了。

Dim olApp As Outlook.Application
Dim myMail As MailItem

    Set olApp = Outlook.Application
    Set myMail = olApp.CreateItem(olMailItem)

Do While Not rsTemp.EOF
    With myMail
        .Recipients.Add  rsTemp("收件人地址")
        .CC =rsTemp("抄送地址")
        .BCC = rsTemp("收件人地址")
        .Subject = rsTemp("主题")
        .Body = rsTemp("正文")
        .Attachments.Add rsTemp("附件地址")
        '.Save
        .Send
    End With
         rsTemp.MoveNext
   Loop

最后关闭记录集,释放变量

   rsTemp.Close
    Set rsTemp = Nothing
    Set conn = Nothing



[此贴子已经被作者于2006-6-16 20:22:24编辑过]


作者: weiw3    时间: 2006-6-17 05:33
呵呵,我其实是从零开始啊!现在正在看关于ADO的帮助文件。还是不懂的话就又要劳烦版主了[em10]




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3