TextBox Text an Email Senden

  • VB.NET

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von GermanElectronix.

    TextBox Text an Email Senden

    Hey Leute,
    Ich habe eine TextBox und wenn ich z.B. in der TextBox "lol" eingebe und ich mit einem Button auf Senden drücken möchte ich das der Text der dort drin steht an meine Email gesendet wird. Kann mir einer sagen wie es Funktioniert? Und bitte ohne das der Absender ein Passwort eingeben muss.. wäre sehr Dankbar dafür.

    LG
    Threadtitel angepasst

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „FlashTek“ ()

    geht nicht da du dich über pop3 bei deinen Email-Server melden must (mit pw und username).
    ich würde dir auch raten es nicht über hardcodet PWs und Usernames zu machen da man innerhalb von 1 min alle pws hat die du drin geschrieben hast :)
    mach es am besten mit php und sende ein HTTP-Request an die PHP Datei und sie sendet dan eine Email an den Adressaten.
    MFG 0x426c61636b4e6574776f726b426974
    InOffical VB-Paradise IRC-Server
    webchat.freenode.net/
    Channel : ##vbparadise
    Spielst du hier jetzt rechte Tasche linke Tasche? Ein Topic genügt dir ja wohl. Wenn du konkrete Probleme hast hilft dir auch jemand, aber wenn das jetzt wieder auf Codebettelei hinausläuft ist das echt arm.
    Im anderen Thread hat dir auch jemand ein Link für SMTP gepostet. Mach dir einfach ein Schrottkonto das bei passwort sowie name keine Relation zu dir hat. Oder aber die php Liebhaber haben ne Alternative parat....

    8-) faxe1008 8-)
    Dazu brauchst du einen Server. Ein kostenloser PHP-Server / Webspace reicht da.

    VB.NET-Quellcode

    1. with new threading.thread(sub()
    2. with new net.webclient()
    3. .downloadstring("http://deineadresse.de/mail.php?msg=" & msg.text)
    4. invoke(sub()
    5. messagebox.show("Mail sent")
    6. end sub)
    7. end with
    8. end sub)
    9. .start()
    10. end with

    PHP-Quellcode

    1. <?php
    2. mail("deine@mail.adresse", "Subject", $_GET["msg"], "");
    3. ?>


    (Weil ich gerade nichts besseres zu tun hatte. Nur aus Kopf geschrieben, kann Fehler enthalten. Kein C&P!).
    Gibt es da nicht noch eine Einfachere Lösung? :) @faxe1008 ?! Wie soll ich das den deiner meinung nach machen? Ich möchte ja das Andere Leute das Programm nützen können, und nicht nur ich!

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „JustTesting“ ()

    @BjöNi
    Wieso einen Thread, wenn es eine Async-Funktion des Webclients gibt?

    VB.NET-Quellcode

    1. Dim wc As New Net.WebClient() With {.Proxy = Nothing}
    2. AddHandler wc.DownloadStringCompleted, Sub(s As Object, c As System.ComponentModel.AsyncCompletedEventArgs)
    3. MessageBox.Show("Mail gesendet")
    4. DirectCast(s, Net.WebClient).Dispose()
    5. End Sub
    6. wc.DownloadStringAsync("http://deineadresse.de/mail.php?msg=" & msg.text)


    JustTesting schrieb:

    Gibt es da nicht noch eine Einfachere Lösung?

    Nein, dies ist die beste und einfachste Lösung.
    Mfg
    Vincent

    VincentTB schrieb:

    Wieso einen Thread, wenn es eine Async-Funktion des Webclients gibt?
    Kann man machen, ist aber im Prinzip sowieso das gleiche:
    System.Net.WebClient: DownloadStringAsync

    VB.NET-Quellcode

    1. ' System.Net.WebClient
    2. ''' <summary>Lädt die angegebene Zeichenfolge in die angegebene Ressource herunter.Durch diese Methode wird der aufrufende Thread nicht blockiert.</summary>
    3. ''' <param name="address">Ein <see cref="T:System.Uri" /> mit dem herunterzuladenden URI.</param>
    4. ''' <param name="userToken">Ein benutzerdefiniertes Objekt, das bei Abschluss des asynchronen Vorgangs an die aufgerufene Methode übergeben wird.</param>
    5. ''' <exception cref="T:System.Net.WebException">Der durch Kombinieren von <see cref="P:System.Net.WebClient.BaseAddress" /> und <paramref name="address" /> gebildete URI ist ungültig.– oder – Fehler beim Herunterladen der Ressource. </exception>
    6. <HostProtection(SecurityAction.LinkDemand, ExternalThreading = True)>
    7. Public Sub DownloadStringAsync(address As Uri, userToken As Object)
    8. If Logging.[On] Then
    9. Logging.Enter(Logging.Web, Me, "DownloadStringAsync", address)
    10. End If
    11. If address Is Nothing Then
    12. Throw New ArgumentNullException("address")
    13. End If
    14. Me.InitWebClientAsync()
    15. Me.ClearWebClientState()
    16. Dim asyncOperation As AsyncOperation = AsyncOperationManager.CreateOperation(userToken)
    17. Me.m_AsyncOp = asyncOperation
    18. Try
    19. Dim request As WebRequest = Me.m_WebRequest = Me.GetWebRequest(Me.GetUri(address))
    20. Me.DownloadBits(request, Nothing, New CompletionDelegate(Me.DownloadStringAsyncCallback), asyncOperation)
    21. Catch ex As Exception
    22. If TypeOf ex Is ThreadAbortException OrElse TypeOf ex Is StackOverflowException OrElse TypeOf ex Is OutOfMemoryException Then
    23. Throw
    24. End If
    25. If Not(TypeOf ex Is WebException) AndAlso Not(TypeOf ex Is SecurityException) Then
    26. ex = New WebException(SR.GetString("net_webclient"), ex)
    27. End If
    28. Me.DownloadStringAsyncCallback(Nothing, ex, asyncOperation)
    29. End Try
    30. If Logging.[On] Then
    31. Logging.[Exit](Logging.Web, Me, "DownloadStringAsync", "")
    32. End If
    33. End Sub
    System.ComponentModel.AsyncOperationManager

    VB.NET-Quellcode

    1. Imports System
    2. Imports System.Security.Permissions
    3. Imports System.Threading
    4. Namespace System.ComponentModel
    5. <HostProtection(SecurityAction.LinkDemand, SharedState = True)>
    6. Public Module AsyncOperationManager
    7. <EditorBrowsable(EditorBrowsableState.Advanced)>
    8. Public Property SynchronizationContext() As SynchronizationContext
    9. Get
    10. If SynchronizationContext.Current Is Nothing Then
    11. SynchronizationContext.SetSynchronizationContext(New SynchronizationContext())
    12. End If
    13. Return SynchronizationContext.Current
    14. End Get
    15. <PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")>
    16. Set(value As SynchronizationContext)
    17. SynchronizationContext.SetSynchronizationContext(value)
    18. End Set
    19. End Property
    20. Public Function CreateOperation(userSuppliedState As Object) As AsyncOperation
    21. Return AsyncOperation.CreateOperation(userSuppliedState, AsyncOperationManager.SynchronizationContext)
    22. End Function
    23. End Module
    24. End Namespace
    System.ComponentModel.AsyncOperation

    VB.NET-Quellcode

    1. Imports System
    2. Imports System.Runtime
    3. Imports System.Security.Permissions
    4. Imports System.Threading
    5. Namespace System.ComponentModel
    6. <HostProtection(SecurityAction.LinkDemand, SharedState = True)>
    7. Public Class AsyncOperation
    8. Private syncContext As SynchronizationContext
    9. Private userSuppliedState As Object
    10. Private alreadyCompleted As Boolean
    11. Public ReadOnly Property UserSuppliedState() As Object
    12. <TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>
    13. Get
    14. Return Me.userSuppliedState
    15. End Get
    16. End Property
    17. Public ReadOnly Property SynchronizationContext() As SynchronizationContext
    18. <TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>
    19. Get
    20. Return Me.syncContext
    21. End Get
    22. End Property
    23. Sub Finalize()
    24. If Not Me.alreadyCompleted AndAlso Me.syncContext IsNot Nothing Then
    25. Me.syncContext.OperationCompleted()
    26. End If
    27. End Sub
    28. Public Sub Post(d As SendOrPostCallback, arg As Object)
    29. Me.VerifyNotCompleted()
    30. Me.VerifyDelegateNotNull(d)
    31. Me.syncContext.Post(d, arg)
    32. End Sub
    33. Public Sub PostOperationCompleted(d As SendOrPostCallback, arg As Object)
    34. Me.Post(d, arg)
    35. Me.OperationCompletedCore()
    36. End Sub
    37. Public Sub OperationCompleted()
    38. Me.VerifyNotCompleted()
    39. Me.OperationCompletedCore()
    40. End Sub
    41. Friend Shared Function CreateOperation(userSuppliedState As Object, syncContext As SynchronizationContext) As AsyncOperation
    42. Return New AsyncOperation(userSuppliedState, syncContext)
    43. End Function
    44. Private Sub New(userSuppliedState As Object, syncContext As SynchronizationContext)
    45. Me.userSuppliedState = userSuppliedState
    46. Me.syncContext = syncContext
    47. Me.alreadyCompleted = False
    48. Me.syncContext.OperationStarted()
    49. End Sub
    50. Private Sub OperationCompletedCore()
    51. Try
    52. Me.syncContext.OperationCompleted()
    53. Finally
    54. Me.alreadyCompleted = True
    55. GC.SuppressFinalize(Me)
    56. End Try
    57. End Sub
    58. Private Sub VerifyNotCompleted()
    59. If Me.alreadyCompleted Then
    60. Throw New InvalidOperationException(SR.GetString("Async_OperationAlreadyCompleted"))
    61. End If
    62. End Sub
    63. Private Sub VerifyDelegateNotNull(d As SendOrPostCallback)
    64. If d Is Nothing Then
    65. Throw New ArgumentNullException(SR.GetString("Async_NullDelegate"), "d")
    66. End If
    67. End Sub
    68. End Class
    69. End Namespace
    System.Threading.SynchronizationContext

    VB.NET-Quellcode

    1. Imports System
    2. Imports System.Runtime
    3. Imports System.Runtime.CompilerServices
    4. Imports System.Runtime.ConstrainedExecution
    5. Imports System.Runtime.InteropServices
    6. Imports System.Security
    7. Imports System.Security.Permissions
    8. Namespace System.Threading
    9. <__DynamicallyInvokable()>
    10. <SecurityPermission(SecurityAction.InheritanceDemand, Flags = (SecurityPermissionFlag.ControlEvidence Or SecurityPermissionFlag.ControlPolicy))>
    11. Public Class SynchronizationContext
    12. Private _props As SynchronizationContextProperties
    13. Private Shared s_cachedPreparedType1 As Type
    14. Private Shared s_cachedPreparedType2 As Type
    15. Private Shared s_cachedPreparedType3 As Type
    16. Private Shared s_cachedPreparedType4 As Type
    17. Private Shared s_cachedPreparedType5 As Type
    18. <SecurityCritical()>
    19. Private Shared s_winRTContextFactory As WinRTSynchronizationContextFactoryBase
    20. <__DynamicallyInvokable()>
    21. Public Shared ReadOnly Property Current() As SynchronizationContext
    22. <__DynamicallyInvokable(), TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")>
    23. Get
    24. Return If(Thread.CurrentThread.GetExecutionContextReader().SynchronizationContext, SynchronizationContext.GetThreadLocalContext())
    25. End Get
    26. End Property
    27. Friend Shared ReadOnly Property CurrentNoFlow() As SynchronizationContext
    28. <FriendAccessAllowed()>
    29. Get
    30. Return If(Thread.CurrentThread.GetExecutionContextReader().SynchronizationContextNoFlow, SynchronizationContext.GetThreadLocalContext())
    31. End Get
    32. End Property
    33. <__DynamicallyInvokable(), TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>
    34. Public Sub New()
    35. End Sub
    36. <SecuritySafeCritical()>
    37. Protected Sub SetWaitNotificationRequired()
    38. Dim type As Type = MyBase.[GetType]()
    39. If SynchronizationContext.s_cachedPreparedType1 IsNot type AndAlso SynchronizationContext.s_cachedPreparedType2 IsNot type AndAlso SynchronizationContext.s_cachedPreparedType3 IsNot type AndAlso SynchronizationContext.s_cachedPreparedType4 IsNot type AndAlso SynchronizationContext.s_cachedPreparedType5 IsNot type Then
    40. RuntimeHelpers.PrepareDelegate(New WaitDelegate(Me.Wait))
    41. If SynchronizationContext.s_cachedPreparedType1 Is Nothing Then
    42. SynchronizationContext.s_cachedPreparedType1 = type
    43. Else
    44. If SynchronizationContext.s_cachedPreparedType2 Is Nothing Then
    45. SynchronizationContext.s_cachedPreparedType2 = type
    46. Else
    47. If SynchronizationContext.s_cachedPreparedType3 Is Nothing Then
    48. SynchronizationContext.s_cachedPreparedType3 = type
    49. Else
    50. If SynchronizationContext.s_cachedPreparedType4 Is Nothing Then
    51. SynchronizationContext.s_cachedPreparedType4 = type
    52. Else
    53. If SynchronizationContext.s_cachedPreparedType5 Is Nothing Then
    54. SynchronizationContext.s_cachedPreparedType5 = type
    55. End If
    56. End If
    57. End If
    58. End If
    59. End If
    60. End If
    61. Me._props = Me._props Or SynchronizationContextProperties.RequireWaitNotification
    62. End Sub
    63. Public Function IsWaitNotificationRequired() As Boolean
    64. Return(Me._props And SynchronizationContextProperties.RequireWaitNotification) <> SynchronizationContextProperties.None
    65. End Function
    66. <__DynamicallyInvokable()>
    67. Public Overridable Sub Send(d As SendOrPostCallback, state As Object)
    68. d(state)
    69. End Sub
    70. <__DynamicallyInvokable()>
    71. Public Overridable Sub Post(d As SendOrPostCallback, state As Object)
    72. ThreadPool.QueueUserWorkItem(New WaitCallback(d.Invoke), state)
    73. End Sub
    74. <__DynamicallyInvokable()>
    75. Public Overridable Sub OperationStarted()
    76. End Sub
    77. <__DynamicallyInvokable()>
    78. Public Overridable Sub OperationCompleted()
    79. End Sub
    80. <CLSCompliant(False), PrePrepareMethod(), SecurityCritical()>
    81. Public Overridable Function Wait(waitHandles As IntPtr(), waitAll As Boolean, millisecondsTimeout As Integer) As Integer
    82. If waitHandles Is Nothing Then
    83. Throw New ArgumentNullException("waitHandles")
    84. End If
    85. Return SynchronizationContext.WaitHelper(waitHandles, waitAll, millisecondsTimeout)
    86. End Function
    87. <CLSCompliant(False), PrePrepareMethod(), ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), SecurityCritical()>
    88. <MethodImpl(MethodImplOptions.InternalCall)>
    89. Protected Shared Function WaitHelper(waitHandles As IntPtr(), waitAll As Boolean, millisecondsTimeout As Integer) As Integer
    90. <__DynamicallyInvokable(), TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries"), SecurityCritical()>
    91. Public Shared Sub SetSynchronizationContext(syncContext As SynchronizationContext)
    92. Dim mutableExecutionContext As ExecutionContext = Thread.CurrentThread.GetMutableExecutionContext()
    93. mutableExecutionContext.SynchronizationContext = syncContext
    94. mutableExecutionContext.SynchronizationContextNoFlow = syncContext
    95. End Sub
    96. <TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")>
    97. Private Shared Function GetThreadLocalContext() As SynchronizationContext
    98. Dim synchronizationContext As SynchronizationContext = Nothing
    99. If synchronizationContext Is Nothing AndAlso Environment.IsWinRTSupported Then
    100. synchronizationContext = SynchronizationContext.GetWinRTContext()
    101. End If
    102. Return synchronizationContext
    103. End Function
    104. <SecuritySafeCritical()>
    105. Private Shared Function GetWinRTContext() As SynchronizationContext
    106. If Not AppDomain.IsAppXModel() Then
    107. Return Nothing
    108. End If
    109. Dim winRTDispatcherForCurrentThread As Object = SynchronizationContext.GetWinRTDispatcherForCurrentThread()
    110. If winRTDispatcherForCurrentThread IsNot Nothing Then
    111. Return SynchronizationContext.GetWinRTSynchronizationContextFactory().Create(winRTDispatcherForCurrentThread)
    112. End If
    113. Return Nothing
    114. End Function
    115. <__DynamicallyInvokable()>
    116. Public Overridable Function CreateCopy() As SynchronizationContext
    117. Return New SynchronizationContext()
    118. End Function
    119. <SecurityCritical()>
    120. Private Shared Function GetWinRTSynchronizationContextFactory() As WinRTSynchronizationContextFactoryBase
    121. Dim winRTSynchronizationContextFactoryBase As WinRTSynchronizationContextFactoryBase = SynchronizationContext.s_winRTContextFactory
    122. If winRTSynchronizationContextFactoryBase Is Nothing Then
    123. Dim type As Type = Type.[GetType]("System.Threading.WinRTSynchronizationContextFactory, System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", True)
    124. winRTSynchronizationContextFactoryBase = (SynchronizationContext.s_winRTContextFactory = CType(Activator.CreateInstance(type, True), WinRTSynchronizationContextFactoryBase))
    125. End If
    126. Return winRTSynchronizationContextFactoryBase
    127. End Function
    128. <SecurityCritical(), SuppressUnmanagedCodeSecurity()>
    129. Private Shared Declare Unicode Function GetWinRTDispatcherForCurrentThread Lib "QCall" () As<MarshalAs(UnmanagedType.[Interface])>
    130. Object
    131. <SecurityCritical()>
    132. Private Shared Function InvokeWaitMethodHelper(syncContext As SynchronizationContext, waitHandles As IntPtr(), waitAll As Boolean, millisecondsTimeout As Integer) As Integer
    133. Return syncContext.Wait(waitHandles, waitAll, millisecondsTimeout)
    134. End Function
    135. End Class
    136. End Namespace
    Hier steht noch was zum SynchronizationContext.
    Mail versenden:
    Imports System.Net
    Imports System.Net.Mail
    Imports System.Net.Sockets

    Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
    Try
    Dim MailMessage as new MailMessage
    MailMessage.From = New MailAddress("MailAddress eintragen")
    MailMessage.Sender = New MailAddress("MailAddress eintragen")
    If rbP1.Checked = True Then
    MailMessage.Priority = MailPriority.Low
    ElseIf rbP2.Checked = True Then
    MailMessage.Priority = MailPriority.Normal
    ElseIf rbP3.Checked = True Then
    MailMessage.Priority = MailPriority.High
    End If
    MailMessage.To.Add("MailAddress eintragen")
    MailMessage.Subject = txtBeschreibung.Text
    MailMessage.Body = txtMail.Text

    'create SMTPClient
    SMTPClient.Credentials = New NetworkCredential("MailAddress", "Mein Mail Passwort")
    SMTPClient.Host = "Meine Mail SMTP"
    SMTPClient.Port = "Mein SMTP Port"
    SMTPClient.EnableSsl = True 'Mail SSL aktivieren

    'send Mail
    SMTPClient.Send(MailMessage)

    CreateObject("sapi.spvoice").speak("Die Mail wurde versendet.")
    Catch ex As Exception
    CreateObject("sapi.spvoice").speak("Die Mail konnte nicht versendet werden.")
    End Try
    End Sub