0

我正在使用 Outlook 2010 的 VBA 宏,它将每封传入的电子邮件保存为一个文件。这有效,来源如下:

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Set Ns = Application.GetNamespace("MAPI")
  Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
  If TypeOf Item Is Outlook.MailItem Then
    SaveMailAsFile Item
  End If
End Sub

Private Sub SaveMailAsFile(oMail As Outlook.MailItem)
  Dim dtDate As Date
  Dim sName As String
  Dim sFile As String
  Dim sExt As String
  
  sPath = "C:\bult\mail\"
  sExt = ".msg"
  sName = oMail.Subject
  ReplaceCharsForFileName sName, "_"
  dtDate = oMail.ReceivedTime
  sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
    vbUseSystem) & Format(dtDate, "-hhnnss", _
    vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & sExt

  oMail.SaveAs sPath & sName, olSaveAsMsg
End Sub

Private Sub ReplaceCharsForFileName(sName As String, _
  sChr As String _
)
  sName = Replace(sName, "/", sChr)
  sName = Replace(sName, "", sChr)
  sName = Replace(sName, ":", sChr)
  sName = Replace(sName, "?", sChr)
  sName = Replace(sName, Chr(34), sChr)
  sName = Replace(sName, "<", sChr)
  sName = Replace(sName, ">", sChr)
  sName = Replace(sName, "|", sChr)
End Sub

问题一旦保存为文件,就会添加原始电子邮件中没有的换行符。例如,下面的单行字符串最终被分成 4 行:

1:[POST]^testcompany^TEST009^7/20/21 Cleveland, OH 44101 03:00 PM - 05:00 PM ^培训课程^7-20-21 Cleveland, OH^42141^State:1^CFP:1 ^CIMA:1^CPE:0^CPFA:0^CHFC:0^CLU:0^CRPC:0^CRPS:0^7/20/21^Cleveland, OH 44101^03:00 PM - 05:00 PM^

将电子邮件另存为文件时,为了保持与原始电子邮件中的行结构完全相同,我可以做些什么不同的事情?

4

0 回答 0