Send en mail i .NET 2.0
Til at sende en mail er der i .NET 2.0 kommet et nyt namespace: System.Net.Mail.SmtpClient. På nette har jeg fundet noget kode til at sende en mail, men det virker ikke helt:Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'create the mail message
Dim mail As New Net.Mail.MailMessage()
'set the addresses
mail.From = New Net.Mail.MailAddress("x@x.dk")
mail.To.Add("y@y.dk")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is the body content of the email."
'send the message
Dim smtp As New Net.Mail.SmtpClient("127.0.0.1")
'to authenticate we set the username and password properites on the
SmtpClientsmtp.Credentials = New Net.CredentialCache("username", "secret")
smtp.Send(mail)
End Sub
Den brokker sig over SmtpClientsmtp - hvad er der galt?