我需要在要求时提交电子邮件。
我的以下代码有效:
潜在解决方案:
优缺点
问题
有谁知道如何向“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
最佳答案
CodeProject.com上的Allan Eagle创建了一个extension of the System.Net.Mail.MailMessage class,其中包括使用特定文件名保存电子邮件的功能。我相信这将解决您提出的问题。
关于c# - 使用System.Net.Mail.MailAddress或其他库指定.eml文件名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29988040/