Ich war Absender von E-Mails in vb.net codiert und es gibt Syntaxfehler. Code unten:Syntax Fehler in 'Neu'
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
Der Fehler ist in New SmtpClient
@PloxorPB Gern geschehen. Im Allgemeinen war Ihr Problem in der Reihe, beginnend mit "neu". Ich habe es gerade getestet, es funktioniert nicht in Vb. So etwas wie - ('new class()). DoSomething funktioniert in C#. Aber nicht in vb. Aber auch hier können komplexe Initialisierer bei Debugging-Problemen nachteilig sein. –