发送电子邮件的ASP.NET应用程序的System.Array错误
我在我创建的应用程序中收到一组错误,这些错误应该是发送电子邮件。任何帮助都将不胜感激。谢谢 以下是一组错误: 错误1“SmtpServer”不是“System.Net.Mail.SmtpClient”的成员。96 9发送电子邮件发送电子邮件的ASP.NET应用程序的System.Array错误,asp.net,vb.net,sendmail,Asp.net,Vb.net,Sendmail,我在我创建的应用程序中收到一组错误,这些错误应该是发送电子邮件。任何帮助都将不胜感激。谢谢 以下是一组错误: 错误1“SmtpServer”不是“System.Net.Mail.SmtpClient”的成员。96 9发送电子邮件 Imports System.Net.Mail Public Class SendEmail Inherits System.Windows.Forms.Form ' Variable which will send the mail Dim
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
错误2“To”不是“System.Array”的成员。100 9发送电子邮件
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
错误3“From”不是“System.Array”的成员。104 9发送电子邮件
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
错误4“isBodyHtml”不是“System.Array”的成员。109 13发送电子邮件
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
错误5未声明名称“MailFormat”。109 34发送电子邮件
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
错误6“BodyFormat”不是“System.Array”的成员。
111 13发送电子邮件
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
错误7未声明名称“MailFormat”。111 34发送电子邮件
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
错误8“Subject”不是“System.Array”的成员。120 9发送电子邮件
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
错误9“附件”不是“System.Array”的成员。125 13发送电子邮件
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
错误10“正文”不是“System.Array”的成员。129 9发送电子邮件
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
错误11“System.Net.Mail.MailMessage的一维数组”类型的值无法转换为“System.Net.Mail.MailMessage”。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.Net.Mail.MailMessage 我在下面改了读
Dim MailMsg As New System.Net.Mail.MailMessage()
在第一个声明中,使用括号声明了一个MailMsg数组。添加新的构造函数将生成有效的构造函数
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
你改变了什么?纯代码答案的质量不高。@Jeremy,我看不出这个答案有任何变化。你能澄清一下吗?谢谢。您已将MailMsg声明为数组。数组没有From或To属性。将声明更改为此注释括号已被删除:Dim MailMsg As System.Net.Mail。MailMessage@Chris,谢谢你的回复。我按照指示更改了该声明,现在我收到以下错误:错误1 SmtpServer不是System.Net.Mail.SmtpClient的成员。95; 错误2属性“To”为“只读”。99; 错误3“字符串”类型的值无法转换为“System.Net.Mail.MailAddress”。103; 错误4未声明名称“MailFormat”。108;错误5“BodyFormat”不是“System.Net.Mail.MailMessage”的成员。110错误6未声明名称“MailFormat”。110