Mail versenden und empfangen...

  • VB.NET

Es gibt 22 Antworten in diesem Thema. Der letzte Beitrag () ist von Marcus Gräfe.

    ich hab es so gemacht:


    VB.NET-Quellcode

    1. Imports System
    2. Imports System.Net
    3. Imports System.Net.Sockets
    4. Imports System.Text
    5. Imports System.io
    6. Imports System.Threading
    7. Public Class Form1
    8. Inherits System.Windows.Forms.Form
    9. Public stream As NetworkStream
    10. Public sr As StreamReader
    11. Private Sub cmdPOPen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPOPen.Click
    12. Dim server As String = "pop.test.de"
    13. Dim user As String = "test"
    14. Dim password As String = "test123"
    15. Dim client As New TcpClient(server, 110)
    16. stream = client.GetStream()
    17. sr = New StreamReader(stream)
    18. txtResponse.Text += sendCommand("?")
    19. txtResponse.Text += sendCommand("USER " + user)
    20. txtResponse.Text += sendCommand("PASS " + password)
    21. txtResponse.Text += sendCommand("STAT" + vbCrLf)
    22. txtResponse.Text += sendCommand("RETR 1" + vbCrLf) 'hole erstes Mail
    23. txtResponse.Text += sendCommand("QUIT" + vbCrLf)
    24. End Sub
    25. Private Function sendCommand(ByVal send As String) As String
    26. send += vbCrLf
    27. Dim data As [Byte]() = Encoding.ASCII.GetBytes(send)
    28. stream.Write(data, 0, data.Length)
    29. sr = New StreamReader(stream)
    30. Dim buffer As New StringBuilder
    31. Do While sr.Peek() > 0
    32. Thread.Sleep(100)
    33. buffer.Append(sr.ReadLine + vbCrLf)
    34. Loop
    35. Return buffer.ToString
    36. End Function
    37. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    38. End Sub
    39. End Class


    wie kann ich, wenn eine email einen Anhang hat. diesen in einen bestimmten Ordner speichern?

    Marvin schrieb:

    Hallo, Ich wollte ein Programm machen das eine e-mail versendet... nur da komme ich nicht so weit :
    So was:

    VB.NET-Quellcode

    1. Imports System.Net.Mail
    2. Public Class Form1
    3. Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    4. Dim NeueNachricht As New MailMessage
    5. Try
    6. NeueNachricht.From = New MailAddress(TextBox2.Text)
    7. NeueNachricht.To.Add(TextBox3.Text)
    8. NeueNachricht.Subject = "Test"
    9. NeueNachricht.Body = "Test"
    10. Dim smtp As New SmtpClient("smtp.web.de")
    11. smtp.Port = 587
    12. smtp.EnableSsl = True
    13. smtp.Credentials = New System.Net.NetworkCredential(TextBox2.Text, TextBox1.Text)
    14. smtp.Send(NeueNachricht)
    15. Catch ex As Exception
    16. Call MsgBox("Sendevorgang fehlgeschlagen!", MsgBoxStyle.Critical, "Error")
    17. End Try
    18. End Sub
    19. End Class
    ?