vb.netで電子メールの送信者をコーディングしていて、構文エラーが発生しています。以下のコード:'New'の構文エラー
Try
Dim message As New MailMessage With {
.Subject = Me.SubjectTxt.Text
}
message.To.Add(Me.ReceiverTxt.Text)
message.From = New MailAddress(Me.EmailTxt.Text)
message.Body = Me.BodyTxt.Text
Dim num2 As Integer = (Me.AttachmentListbox.Items.Count - 1)
Dim i As Integer = 0
Do While (i <= num2)
Dim item As New Attachment(Conversions.ToString(Me.AttachmentListbox.Items.Item(i)))
message.Attachments.Add(item)
i += 1
Loop
New SmtpClient(Me.ClientBox.Text) With { _
.EnableSsl = True, _
.Credentials = New NetworkCredential(Me.EmailTxt.Text, Me.PasswordTxt.Text), _
.Port = Conversions.ToInteger(Me.PortTxt.Text) _
}.Send(message)
Interaction.MsgBox(("Message sent to " & Me.ReceiverTxt.Text), MsgBoxStyle.Information, "SMTP Email Sender")
Catch exception1 As Exception
ProjectData.SetProjectError(exception1)
Dim exception As Exception = exception1
If (Me.ReceiverTxt.Text = Nothing) Then
Interaction.MsgBox("Please fill up the Receiver.", MsgBoxStyle.Exclamation, "You missed something!")
ElseIf (Me.SubjectTxt.Text = Nothing) Then
Interaction.MsgBox("Please fill up Subject.", MsgBoxStyle.Exclamation, "You missed something!")
ElseIf (Me.BodyTxt.Text = Nothing) Then
Interaction.MsgBox("Please fill up the Message Body.", MsgBoxStyle.Exclamation, "You missed something!")
ElseIf (Me.EmailTxt.Text = Nothing) Then
Interaction.MsgBox("Please fill up the Email for Account Log In.", MsgBoxStyle.Exclamation, "You missed something!")
ElseIf (Me.PasswordTxt.Text = Nothing) Then
Interaction.MsgBox("Please fill up the Password for Account Log In.", MsgBoxStyle.Exclamation, "You missed something!")
ElseIf (Me.ClientBox.Text = Nothing) Then
Interaction.MsgBox("Please fill up the Server for basis of SMTP Server.", MsgBoxStyle.Exclamation, "You missed something!")
ElseIf (Me.PortTxt.Text = Nothing) Then
Interaction.MsgBox("Please fill up the Port to successfully send the email.", MsgBoxStyle.Exclamation, "You missed something!")
Else
Interaction.MsgBox("Sending Failed", DirectCast(Conversions.ToInteger("SMTP Email Sender"), MsgBoxStyle), Nothing)
End If
ProjectData.ClearProjectError()
End Try
エラーが初期化子のNew SmtpClient
@PloxorPBよろしくお願いいたします。一般に、あなたの問題は 'new'で始まる行にありました。私はちょうどそれをテストした、それはVBで動作しません。このような何か - ( 'new class())。DoSomething'はC#で動作します。しかし、VBではない。しかし、やはり、複雑なイニシャライザはデバッグの問題に悪影響を与える可能性があります。 –