我创建的这个应用程序中出现了一组错误,应该发送电子邮件。任何帮助都将不胜感激。谢谢以下是一组错误:
错误1"SmtpServer"不是"System"的成员。网邮政SmtpClient'。96 9发送电子邮件
错误2"To"不是"System"的成员。数组'。100 9发送电子邮件
错误3"From"不是"System"的成员。数组'。104 9发送电子邮件
错误4"isBodyHtml"不是"System"的成员。数组'。109 13发送电子邮件
错误5未声明名称"MailFormat"。109 34发送电子邮件
错误6"BodyFormat"不是"System"的成员。数组'
111 13发送电子邮件
错误7未声明名称"MailFormat"。111 34发送电子邮件
错误8"主题"不是"系统"的成员。数组'。120 9发送电子邮件
错误9"Attachments"不是"System"的成员。数组'。125 13发送电子邮件
错误10"Body"不是"System"的成员。数组'。129 9发送电子邮件
错误11"系统的一维数组"类型的值。网邮政MailMessage"无法转换为"System"。"。网邮政邮件信息'.132 18发送电子邮件
Imports System.Net.Mail
Public Class SendEmail
Inherits System.Windows.Forms.Form
' Variable which will send the mail
Dim obj As _
System.Net.Mail.SmtpClient
'Variable to store the attachments
Dim Attachment As System.Net.Mail.Attachment
'Variable to create the message to send
Dim MailMsg As System.Net.Mail.MailMessage()
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim Counter As Integer
'Validate the data
If txtSMTPServer.Text = "" Then
MsgBox("Enter the SMTP server info ...!!!", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If
If txtFrom.Text = "" Then
MsgBox("Enter the From email address ...!!!", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If
If txtTo.Text = "" Then
MsgBox("Enter the Recipient email address ...!!!", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If
If txtSubject.Text = "" Then
MsgBox("Enter the Email subject ...!!!", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If
'Set the properties
'Assign the SMTP server
obj.SmtpServer = txtSMTPServer.Text
'Multiple recepients can be specified using ; as the delimeter
'Address of the recipient
MailMsg.To = txtTo.Text
'Your From Address
'You can also use a custom header Reply-To for a different replyto address
MailMsg.From = "" & txtFromDisplayName.Text & " <" & txtFrom.Text & ">"
'Specify the body format
If chkFormat.Checked = True Then
MailMsg.isBodyHtml = MailFormat.Html 'Send the mail in HTML Format
Else
MailMsg.BodyFormat = MailFormat.Text
End If
'If you want you can add a reply to header
'Mailmsg.Headers.Add("Reply-To", "testmail@mail.com")
'custom headersare added like this
'Mailmsg.Headers.Add("Manoj", "TestHeader")
'Mail Subject
MailMsg.Subject = txtSubject.Text
'Attach the files one by one
For Counter = 0 To lstAttachment.Items.Count - 1
Attachment = New Net.Mail.Attachment(lstAttachment.Items(Counter))
'Add it to the mail message
MailMsg.Attachments.Add(Attachment)
Next
'Mail Body
MailMsg.Body = txtMessage.Text
'Call the send method to send the mail
obj.Send(MailMsg)
End Sub
End Class
这一行是一个问题:Dim MailMsg As System。网邮政邮件()我在下面改为阅读
Dim MailMsg As New System.Net.Mail.MailMessage()
在第一个带有括号的声明中,声明了一个MailMsg数组。添加New将生成一个有效的构造函数。
Imports System.Net.Mail
Public Class SendEmail
Inherits System.Windows.Forms.Form
' Variable which will send the mail
Dim obj As _
System.Net.Mail.SmtpClient
'Variable to store the attachments
Dim Attachment As System.Net.Mail.Attachment
'Variable to create the message to send
Dim MailMsg As New System.Net.Mail.MailMessage()
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim Counter As Integer
'Validate the data
If txtSMTPServer.Text = "" Then
MsgBox("Enter the SMTP server info ...!!!", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If
If txtFrom.Text = "" Then
MsgBox("Enter the From email address ...!!!", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If
If txtTo.Text = "" Then
MsgBox("Enter the Recipient email address ...!!!", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If
If txtSubject.Text = "" Then
MsgBox("Enter the Email subject ...!!!", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If
'Set the properties
'Assign the SMTP server
obj.SmtpServer = txtSMTPServer.Text
'Multiple recepients can be specified using ; as the delimeter
'Address of the recipient
MailMsg.To = txtTo.Text
'Your From Address
'You can also use a custom header Reply-To for a different replyto address
MailMsg.From = "" & txtFromDisplayName.Text & " <" & txtFrom.Text & ">"
'Specify the body format
If chkFormat.Checked = True Then
MailMsg.isBodyHtml = MailFormat.Html 'Send the mail in HTML Format
Else
MailMsg.BodyFormat = MailFormat.Text
End If
'If you want you can add a reply to header
'Mailmsg.Headers.Add("Reply-To", "testmail@mail.com")
'custom headersare added like this
'Mailmsg.Headers.Add("Manoj", "TestHeader")
'Mail Subject
MailMsg.Subject = txtSubject.Text
'Attach the files one by one
For Counter = 0 To lstAttachment.Items.Count - 1
Attachment = New Net.Mail.Attachment(lstAttachment.Items(Counter))
'Add it to the mail message
MailMsg.Attachments.Add(Attachment)
Next
'Mail Body
MailMsg.Body = txtMessage.Text
'Call the send method to send the mail
obj.Send(MailMsg)
End Sub
End Class