VBScript SMTP服务器

VBScript SMTP服务器,vbscript,outlook,smtp,Vbscript,Outlook,Smtp,我已将此设置为通过Outlook客户端自动发送电子邮件,是否可以将此代码更改为直接通过SMTP服务器工作?有人能帮我吗 任何帮助都将不胜感激,谢谢 Set app = CreateObject("Excel.Application") Set fso = CreateObject("Scripting.FileSystemObject") For Each f In fso.GetFolder("Y:\Billing_Common\autoemail").Files If LCase(fs

我已将此设置为通过Outlook客户端自动发送电子邮件,是否可以将此代码更改为直接通过SMTP服务器工作?有人能帮我吗

任何帮助都将不胜感激,谢谢

Set app = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")

For Each f In fso.GetFolder("Y:\Billing_Common\autoemail").Files
  If LCase(fso.GetExtensionName(f)) = "xls" Then
    Set wb = app.Workbooks.Open(f.Path)


set sh = wb.Sheets("Auto Email Script")
row = 2
name = "Customer"
email = sh.Range("A" & row)
subject = "Billing"
the = "the"
LastRow = sh.UsedRange.Rows.Count

For r = row to LastRow
    If App.WorkSheetFunction.CountA(sh.Rows(r)) <> 0 Then 
        SendMessage email, name, subject, TRUE, _
        NULL, "Y:\Billing_Common\autoemail\Script\energia-logo.gif", 143,393
        row = row + 1
        email = sh.Range("A" & row)
    End if
Next
wb.Close
End If
Next

Sub SendMessage(EmailAddress, DisplayName, Subject, DisplayMsg, AttachmentPath, ImagePath, ImageHeight, ImageWidth)

  ' Create the Outlook session.
  Set objOutlook = CreateObject("Outlook.Application")

  template = FindTemplate()

  ' Create the message.
  Set objOutlookMsg  = objOutlook.CreateItem(0)

  With objOutlookMsg
      ' Add the To recipient(s) to the message.
      Set objOutlookRecip = .Recipients.Add(EmailAddress)
      objOutlookRecip.resolve
      objOutlookRecip.Type = 1

     ' Set the Subject, Body, and Importance of the message.
     .Subject = Subject
     .bodyformat = 3
     .Importance = 2  'High importance

     body = Replace(template, "{First}", name)
     body = Replace(body, "{the}", the)

     if not isNull(ImagePath) then
       if not ImagePath = "" then
         .Attachments.add ImagePath
         image = split(ImagePath,"\")(ubound(split(ImagePath,"\")))
         body = Replace(body, "{image}", "<img src='cid:" & image & _
         "'" & " height=" & ImageHeight &" width=" & ImageWidth & ">")
       end if
     else
        body = Replace(body, "{image}", "")
     end if

     if not isNull(AttachMentPath) then
       .Attachments.add AttachmentPath
     end if

     .HTMLBody = body
         .Save
         .Send
    End With
    Set objOutlook = Nothing
End Sub

Function FindTemplate()
    Set OL = GetObject("", "Outlook.Application")
    set Drafts = OL.GetNamespace("MAPI").GetDefaultFolder(16)
    Set oItems = Drafts.Items

    For Each Draft In oItems
        If Draft.subject = "Template" Then
            FindTemplate = Draft.HTMLBody
            Exit Function
        End If
    Next
End Function
Set app=CreateObject(“Excel.Application”)
设置fso=CreateObject(“Scripting.FileSystemObject”)
对于fso.GetFolder(“Y:\Billing\u Common\autoemail”)文件中的每个f
如果LCase(fso.GetExtensionName(f))=“xls”,则
设置wb=app.Workbooks.Open(f.Path)
设置sh=wb.Sheets(“自动电子邮件脚本”)
行=2
name=“客户”
email=sh.Range(“A”行和行)
主题=“计费”
the=“the”
LastRow=sh.UsedRange.Rows.Count
对于r=行到最后一行
如果App.WorkSheetFunction.CountA(sh.Rows(r))为0,则
SendMessage电子邮件,名称,主题,TRUE_
空,“Y:\Billing\u Common\autoemail\Script\energia logo.gif”,143393
行=行+1
email=sh.Range(“A”行和行)
如果结束
下一个
wb.关闭
如果结束
下一个
子发送消息(EmailAddress、DisplayName、Subject、DisplayMsg、AttachmentPath、ImagePath、ImageHeight、ImageWidth)
'创建Outlook会话。
设置objOutlook=CreateObject(“Outlook.Application”)
template=FindTemplate()
'创建消息。
设置objOutlookMsg=objOutlook.CreateItem(0)
带objOutlookMsg
'将收件人添加到邮件中。
设置objOutlookRecip=.Recipients.Add(电子邮件地址)
objOutlookRecip.resolve
objOutlookRecip.Type=1
'设置消息的主题、正文和重要性。
.主语
.bodyformat=3
.重要性=2'高度重要性
body=Replace(模板“{First}”,名称)
body=Replace(body,{the},the)
如果不是isNull(ImagePath),则
如果不是ImagePath=“”,则
.Attachments.AddImagePath
image=split(ImagePath,“\”)(ubound(split(ImagePath,“\”))
body=Replace(body,{image},“”)
如果结束
其他的
body=Replace(body,{image},“”)
如果结束
如果不是isNull(AttachMentPath),则
.Attachments.add AttachmentPath
如果结束
.HTMLBody=主体
拯救
邮寄
以
设置objOutlook=Nothing
端接头
函数FindTemplate()
Set OL=GetObject(“,”Outlook.Application“)
设置Drafts=OL.GetNamespace(“MAPI”).GetDefaultFolder(16)
设置oItems=Drafts.Items
以oItems表示的每份汇票
如果Draft.subject=“Template”,则
FindTemplate=Draft.HTMLBody
退出功能
如果结束
下一个
端函数

如果要将邮件直接发送到SMTP服务器,首先不需要通过Outlook。就用吧。大概是这样的:

schema = "http://schemas.microsoft.com/cdo/configuration/"

Set msg = CreateObject("CDO.Message")
msg.Subject  = "Test"
msg.From     = "sender@example.com"
msg.To       = "recipient@example.org"
msg.TextBody = "This is some sample message text."

With msg.Configuration.Fields
  .Item(schema & "sendusing")      = 2
  .Item(schema & "smtpserver")     = "smtp.intern.example.com"
  .Item(schema & "smtpserverport") = 25
  .Update
End With

msg.Send

如果要将邮件直接发送到SMTP服务器,首先不需要通过Outlook。就用吧。大概是这样的:

schema = "http://schemas.microsoft.com/cdo/configuration/"

Set msg = CreateObject("CDO.Message")
msg.Subject  = "Test"
msg.From     = "sender@example.com"
msg.To       = "recipient@example.org"
msg.TextBody = "This is some sample message text."

With msg.Configuration.Fields
  .Item(schema & "sendusing")      = 2
  .Item(schema & "smtpserver")     = "smtp.intern.example.com"
  .Item(schema & "smtpserverport") = 25
  .Update
End With

msg.Send

谢谢你的回复,但我不知道如何实现CDO。我包括了一个示例和一个链接到一个有更多示例的页面。谢谢你的回复,但我不知道如何实现CDO。我包括了一个示例和一个链接到一个有更多示例的页面。