使用Outlook从网页发送电子邮件

时间:2010-07-02 02:57:37

标签: vbscript outlook outlook-2007

我有一个网页,其中有一个按钮,可以将页面上的一封信发送给电子邮件配方。目前我们使用Lotus Notes和VB脚本,我们可以创建Lotus Notes的对象,该对象的一个​​属性是PutInFolder。用户单击电子邮件按钮后,脚本将发送电子邮件,并将电子邮件保存在用户计算机上的某个文件夹中。我们公司现在正在切换到Outlook 2007,我希望用Outlook对象做同样的事情。我们的开发只是本地Intranet,只有少数用户可以访问它。无论如何,我的问题是我似乎无法找到与Outlook应用程序相同的功能。

我确实发送了当前使用此逻辑的电子邮件。有没有人对如何在用户的Outlook文件夹中保存电子邮件有任何想法?我试着寻找一个我可以打电话但我找不到任何搜索的属性列表。也许我在搜索中没有正确的终点。

谢谢。

sub send_mailvb(sendto, sendcc, sendbcc, subject_text, body_text, attachment1, attachment2, attachment3)

'Open mail, adress, attach report
dim objOutlk    'Outlook
dim objMail 'Email item
dim strMsg
const olMailItem = 0
'Create a new message
    set objOutlk = createobject("Outlook.Application")
    set objMail = objOutlk.createitem(olMailItem)

' Setup send to
    objMail.To = sendto

' Setup send cc
If sendcc <> "" Then
objMail.cc = sendcc
End If

' Setup send bcc
If sendbcc <> "" Then
objMail.bcc = sendbcc
End If

'Set up Subject Line
    objMail.subject = subject_text

'Add the body

    strMsg = body_text & vbcrlf

'Add an attachments
If attachment1 <> "" Then
    objMail.attachments.add(attachment1)
End If

If attachment2 <> "" Then
    objMail.attachments.add(attachment2)
End If

If attachment3 <> "" Then
    objMail.attachments.add(attachment3)
End If

    objMail.body = strMsg
    objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing

'Clean up
set objMail = nothing
set objOutlk = nothing

End Sub

4 个答案:

答案 0 :(得分:2)

供将来参考......我找到了我想要的解决方案。这不是一团糟。这是修改后的源代码,用于复制发送并将电子邮件保存到特定文件夹,以防其他人查看。感谢Tester101我正在寻找的网站。再次,这是嵌入在HTML页面中的vbscript。




    sub send_mailvb(sendto, sendcc, sendbcc, subject_text, body_text, attachment1, attachment2, attachment3)

    'Open mail, adress, attach report  

    dim objOutlk    'Outlook
    dim objMail 'Email item
    dim strMsg
    dim myInbox
    const olMailItem = 0
    'Create a new message
        set objOutlk = createobject("Outlook.Application")
        Set objNameSpace = objOutlk.Session 
        set objMail = objOutlk.createitem(olMailItem)

        Set myNameSpace = objOutlk.GetNamespace("MAPI")

    Set myExplorer = objOutlk.ActiveExplorer


    ' 6 at least on my machine pointed to the Inbox (should be the same as constant olFolderInbox).  Within the Inbox I have a folder called Test
    Set myExplorer.CurrentFolder = myNameSpace.GetDefaultFolder(6).Folders("Test")
    Set myFolder = myExplorer.CurrentFolder

    ' Setup send to
        objMail.To = sendto

    ' Setup send cc
    If sendcc  "" Then
    objMail.cc = sendcc
    End If

    ' Setup send bcc
    If sendbcc  "" Then
    objMail.bcc = sendbcc
    End If

    'Set up Subject Line
        objMail.subject = subject_text

    'Add the body

        strMsg = body_text & vbcrlf

    'Add an attachments
    If attachment1  "" Then
        objMail.attachments.add(attachment1)
    End If

    If attachment2  "" Then
        objMail.attachments.add(attachment2)
    End If

    If attachment3  "" Then
        objMail.attachments.add(attachment3)
    End If

        objMail.body = strMsg
        // objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing


        objMail.Save
        objMail.Move(myFolder)

        objMail.Send

    'Clean up
    set objMail = nothing
    set objOutlk = nothing

    End Sub

答案 1 :(得分:0)

我找到了这篇文章。它可能会有所帮助。

http://www.outlookcode.com/codedetail_print.aspx?id=1041

如果不是这个网站有很好的资源来处理Outlook。

答案 2 :(得分:0)

看起来MailItem对象具有Save方法,以及SaveAs方法。所以你应该可以做这样的事情。

objMail.SaveAs "C:\Test.msg", 3 

3是以olMSG格式保存邮件,请参阅OlSaveAsType Enumeration

答案 3 :(得分:0)

我有一个解决方案。我们决定bcc发送电子邮件的人然后使用outlook规则将电子邮件移动到指定的outlook文件夹。感谢所有回复的人。

相关问题