我需要在要求时提交电子邮件。
我的代码有效:
潜在解决方案:
优点和缺点
问题
是否有人知道如何向" MySpecifiedFileName.eml"提交电子邮件,而无需重命名然后复制?
现有代码:
Public Shared Sub Send(ByVal EmailFrom As String, ByVal EmailTo As String, ByVal Subject As String, ByVal HTMLBody As String, Optional SaveToFile As Boolean = False, Optional SaveFilepath As String = "")
Dim MyMsg As MailMessage = New MailMessage
Dim Recipients() As String
Recipients = Split(EmailTo, ";")
With MyMsg
.From = New System.Net.Mail.MailAddress(EmailFrom)
For i = 0 To Recipients.Count - 1
If Recipients(i).ToString <> "" Then
.To.Add(New System.Net.Mail.MailAddress(Recipients(i)))
End If
Next
.Sender = New System.Net.Mail.MailAddress(EmailFrom)
.Subject = Subject
.Body = HTMLBody
.BodyEncoding = System.Text.Encoding.UTF8
.IsBodyHtml = True
.Priority = MailPriority.High
End With
Dim SmtpServer As New SmtpClient(My.Settings("SMTPServer"))
SmtpServer.Send(MyMsg)
REM
REM Save Email when requested
REM
If SaveToFile = True Then
Dim client As New SmtpClient(My.Settings("SMTPServer"))
client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory
client.PickupDirectoryLocation = SaveFilepath
client.Send(MyMsg)
client = Nothing
End If
MyMsg = Nothing
SmtpServer = Nothing
End Sub
答案 0 :(得分:7)
CodeProject.com上的Allan Eagle创建了一个extension of the System.Net.Mail.MailMessage class,其中包含使用特定文件名保存电子邮件的功能。我相信这会解决你提出的问题。