Imports System.Net.Mail

Public Class frmKundenChangeMail



    Private Function sendMail(kdnr, kdName, aenderung, sb) As Boolean
        Dim Msg As New MailMessage
        Dim myCredentials As New System.Net.NetworkCredential
        myCredentials.UserName = "support@verag.ag"
        myCredentials.Password = "support"
        Msg.IsBodyHtml = True
        Dim mySmtpsvr As New SmtpClient()
        mySmtpsvr.Host = "owa.verag.ag" 'bei web.de
        mySmtpsvr.Port = 25 '587 '25
        mySmtpsvr.UseDefaultCredentials = False
        mySmtpsvr.Credentials = myCredentials
        Try
            Msg.From = New MailAddress("support@verag.ag")
            If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
                Msg.To.Add("al@verag.ag")
            Else
                Msg.To.Add("rechnungsversand@verag.ag") 'rechnungsversand bekommt die Mails
            End If

            Msg.Subject = "Änderung Kundendaten für " & kdnr & " " & kdName
            Msg.Body = ""
            Msg.Body &= "<table style=""font-family:calibri;font-size:14px;"">"
            Msg.Body &= "<tr><td style=""width:150px;"" >Kunden-Nr.:</td><td><b>" & kdnr & "</b><td></tr>"
            Msg.Body &= "<tr><td>Kunde:</td><td><b>" & kdName & "</b><td></tr>"
            Msg.Body &= "<tr><td>Sachbearbeiter:</td><td><b>" & sb & "</b><td></tr>"
            Msg.Body &= "</table>"
            Msg.Body &= "<div style=""font-family:calibri;font-size:14px;"">"
            Msg.Body &= "<br/><br/>"
            Msg.Body &= "Änderung:"
            Msg.Body &= "<br/>"
            Msg.Body &= "<span style=""font-size:18px;"">" & aenderung & "</span>"
            Msg.Body &= "<br/><br/><br/><br/>Automatisch generierte E-Mail. "
            Msg.Body &= "<br/>VERAG Spedition AG"
            Msg.Body &= "</div>"

            Msg.SubjectEncoding = System.Text.Encoding.UTF8
            Msg.BodyEncoding = System.Text.Encoding.UTF8
            Msg.HeadersEncoding = System.Text.Encoding.UTF8

            mySmtpsvr.Send(Msg)
            MsgBox("E-Mail gesendet.", MsgBoxStyle.Information, Title:="Information")
            Return True
        Catch ex As Exception
            MsgBox(Err.Number & ex.Message & ex.StackTrace.ToString) 'Falls ein Fehler auftritt wird eine MsgBox angezeigt
            Return False
        End Try
    End Function


    Private Sub btnAnVerrechnungSenden_Click(sender As Object, e As EventArgs) Handles btnAnVerrechnungSenden.Click
        If sendMail(txtKdNr.Text, txtKdName.Text, rtbAenderung.Text, txtSB.Text) Then
            Me.Close()
        End If
    End Sub

    Private Sub frmKundenChangeMail_Load(sender As Object, e As EventArgs) Handles Me.Load
        txtSB.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME
    End Sub
End Class