Public Class Form1
#Region "Buttons"
'-------------------------<
Region: Buttons >------------------
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
Dim IsSend As Boolean
IsSend = Send_Email(tbxTo.Text, "", tbxFrom.Text, tbxPassword.Text,
tbxDomain.Text, tbxSubject.Text, tbxText.Text)
MsgBox("Email
Status send is: " & IsSend)
End Sub
'-------------------------</
Region: Buttons >------------------
#End Region
#Region "Functions"
'-------------------------<
Region: Functions >------------------
Public Function Send_Email(ByVal TO_Email_Address As String, ByVal CC_Email_Address As String, ByVal FROM_Email_Address As String, ByVal Password As String, ByVal sSMTP As String, ByVal Subject_Title As String, ByVal Text_Body As String, Optional ByVal Attachements_Path As String = "") As Boolean
'-------------------------------< Funktion: Email
erstellen und senden >-------------------------------
'--< Variablen >--
Dim Result_Send As Boolean = False
'--</ Variablen >--
'-<
Kontrolle >-
If TO_Email_Address Like "" Then
MsgBox("Email Adress TO is empty", MsgBoxStyle.Critical, "Send_Email")
Return False
Exit Function
End If
If FROM_Email_Address Like "" Then
MsgBox("Email Adress FROM is empty", MsgBoxStyle.Critical, "Send_Email")
Return False
Exit Function
End If
'-</
Kontrolle >-
Dim arrEmpfaenger As Array
arrEmpfaenger = Split(TO_Email_Address, ";", , CompareMethod.Binary)
If arrEmpfaenger.Length > 1 Then
TO_Email_Address =
arrEmpfaenger(0)
End If
'----<
Email >----
Try
'---< Mailobjekt erzeugen und senden
>--
Dim MailAdress_From As New
System.Net.Mail.MailAddress(FROM_Email_Address)
Dim MailAdress_To As New
System.Net.Mail.MailAddress(TO_Email_Address)
Dim vMail As New
System.Net.Mail.MailMessage(MailAdress_From, MailAdress_To)
'< weitere empfaenger anfuegen >
If arrEmpfaenger.Length > 1 Then
For iAn As Integer = 1 To arrEmpfaenger.Length - 1
vMail.To.Add(arrEmpfaenger(iAn))
Next
End If
'</ weitere empfaenger anfuegen >
If Not CC_Email_Address Like "" Then
'Dim vAdressCC As New
System.Net.Mail.MailAddress(sEMailcc)
Dim arrCC As Array
arrCC =
Split(CC_Email_Address, ";", , CompareMethod.Binary)
For iCC As Integer = 0 To arrCC.Length - 1
vMail.CC.Add(arrCC(iCC))
Next
End If
vMail.IsBodyHtml = True
vMail.Subject = Subject_Title
vMail. = Text_Body
'--< Mailobject >--
'*create mail client and send
Dim objMailClient As New System.Net.Mail.SmtpClient(sSMTP)
objMailClient.UseDefaultCredentials
= False '*either windows login or user-password
objMailClient.Credentials = New
Net.NetworkCredential(FROM_Email_Address, Password)
'<
Senden >
Try
'===== < Achtung : Hier wird gesendet >====
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'debug
objMailClient.Send(vMail)
'/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'< #test
>
'*ansonsten sendasync probieren
objMailClient.Dispose()
'</ #test >
'objMailClient.SendAsync
'===== </ Achtung : Hier wird gesendet >====
'Status_Text = "status=OK /send
to:" & TO_Email_Address & " subject:" &
Subject_Title
Result_Send = True
Catch ex As Exception
'-< Fehler >-
Dim sError As String
If ex.InnerException Is Nothing Then
sError = ex.Message
Else
sError = ex.Message &
vbCrLf & ex.InnerException.Message
End If
MsgBox(sError)
'-</ Fehler >-
End Try
'</
Senden >
'---</
Mailobjekt erzeugen und senden >--
Catch ex As Exception
'-< Fehler >-
Dim sError As String
If ex.InnerException Is Nothing Then
sError = ex.Message
Else
sError = ex.Message &
vbCrLf & ex.InnerException.Message
End If
MsgBox(sError)
'-</ Fehler >-
End Try
'--<
Mailobject >--
'<
Abschluss >
Return Result_Send
'</
Abschluss >
'----</
Email >----
'-------------------------------< Funktion: Email
erstellen und senden >-------------------------------
End Function
'-------------------------</
Region: Functions >------------------
#End Region
End Class
|