Vb.net VB将邮件优先级设置为高
该代码发送电子邮件,工作正常,但出于某种原因,它没有出去的高度重要性。我做错了什么Vb.net VB将邮件优先级设置为高,vb.net,email,module,Vb.net,Email,Module,该代码发送电子邮件,工作正常,但出于某种原因,它没有出去的高度重要性。我做错了什么 Option Explicit On Imports System.IO Imports System.Net.Mail Module SendMail Sub SendMessage() Dim olApp As Object Dim olMail As Object Dim olNs As Object Dim Priority As MailP
Option Explicit On
Imports System.IO
Imports System.Net.Mail
Module SendMail
Sub SendMessage()
Dim olApp As Object
Dim olMail As Object
Dim olNs As Object
Dim Priority As MailPriority
olApp = CreateObject("Outlook.Application")
olNs = olApp.GetNamespace("MAPI")
olMail = olApp.CreateItem(0)
With olMail
olMail.To = "" '// Add recipient
olMail.Cc = ""
olMail.Bcc = ""
olMail.Subject = "New File "
olMail.HTMLBody = "Your File is Ready " & Format(Now, "Long Date")
olMail.Attachments.Add = " " '// Add attachments to the message.
olMail.Priority = MailPriority.High '// High importance
olMail.Send()
End With
olMail = Nothing
olApp = Nothing
olNs = Nothing
End Sub
End Module
尝试改用System.Net.Mail命名空间发送 例如:
Option Strict On
Option Explicit On
Option Infer Off
Imports System.Net.Mail
Public Class Form1
Function SendEmail(ByVal Recipients As List(Of String), _
ByVal FromAddress As String, _
ByVal Subject As String, _
ByVal Body As String, _
ByVal UserName As String, _
ByVal Password As String, _
Optional ByVal Server As String = "smtp.gmail.com", _
Optional ByVal Port As Integer = 587, _
Optional ByVal Attachments As List(Of String) = Nothing) As String
Dim Email As New MailMessage()
Try
Dim SMTPServer As New SmtpClient
For Each Attachment As String In Attachments
Email.Attachments.Add(New Attachment(Attachment))
Next
Email.From = New MailAddress(FromAddress)
For Each Recipient As String In Recipients
Email.To.Add(Recipient)
Next
Email.Subject = Subject
Email.Body = Body
'----------------------------------
Email.Priority = MailPriority.High
'----------------------------------
SMTPServer.Host = Server
SMTPServer.Port = Port
SMTPServer.Credentials = New System.Net.NetworkCredential(UserName, Password)
SMTPServer.EnableSsl = True
SMTPServer.Send(Email)
Email.Dispose()
Return "Email to " & Recipients(0) & " from " & FromAddress & " was sent."
Catch ex As SmtpException
Email.Dispose()
Return "Sending Email Failed. Smtp Error."
Catch ex As ArgumentOutOfRangeException
Email.Dispose()
Return "Sending Email Failed. Check Port Number."
Catch Ex As InvalidOperationException
Email.Dispose()
Return "Sending Email Failed. Check Port Number."
End Try
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Recipients As New List(Of String)
Recipients.Add("SomeEmailAddress")
Dim FromEmailAddress As String = Recipients(0)
Dim Subject As String = "Test From VB."
Dim Body As String = "email body text, if you are reading this from your gmail account, the program worked."
Dim UserName As String = "GMAIL USERNAME WITHOUT (@GMAIL>COM)"
Dim Password As String = "Password"
Dim Port As Integer = 587
Dim Server As String = "smtp.gmail.com"
Dim Attachments As New List(Of String)
MsgBox(SendEmail(Recipients, FromEmailAddress, Subject, Body, UserName, Password, Server, Port, Attachments))
End Sub
End Class
从查看中判断,似乎没有
优先级
属性(您正在尝试设置)。请改为尝试设置
…或者,如果您不需要Outlook功能,只想发送邮件,只需使用.NET自己的邮件即可。“下一步出错时继续”?真正地设置优先级的代码可能会引发异常,而您不会知道。发件人从不设置高优先级。这取决于收件人的电子邮件程序。outlook中存在该属性,用于在您自己的文件夹中设置邮件。我没有使用表单发送电子邮件,我正在尝试从filesystemwatcher自动发送邮件,但每次FileCreatedJust都必须修改代码,但您需要修改代码才能使其与您的应用程序配合使用。它并不是专门为表格制作的。