Imports System.Net.Mail
Imports System.Text
Imports System.IO
Imports Telerik.Web.UI

Namespace PCSolution.Email

    Module Email

        ''' <summary>
        ''' Odeslat e-mail bez přílohy.
        ''' </summary>
        ''' <remarks></remarks>
        Sub OdeslatEmail(ByVal sOdesilatel As String, ByVal sPrijemce As String, ByVal sPredmet As String, _
                         ByVal sZprava As String, Optional ByVal sSMTP As String = "", Optional ByVal sUsername As String = "", Optional ByVal sPassword As String = "", _
                         Optional ByVal iPort As Integer = 25)

            Dim Mail As New System.Net.Mail.MailMessage(sOdesilatel, sPrijemce, sPredmet, _
                                                        "<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">" & _
                                                        "<style>body {font-family: Arial CE, sans-serif;font-size:12px;}</style></head><body>" & _
                                                        sZprava & "</body></html>")

            Mail.IsBodyHtml = True
            Mail.BodyEncoding = Encoding.UTF8

            Dim mySmtp As New Net.Mail.SmtpClient(sSMTP)
            If sUsername <> "" Then
                Dim credential As New System.Net.NetworkCredential(sUsername, sPassword)
                mySmtp.Credentials = credential
            End If
            mySmtp.Port = iPort

            Try
                mySmtp.Send(Mail)
            Catch ex As Exception
                'MsgBox(ex.ToString)
            End Try

            'HttpContext.Current.Response.Write(ex.ToString)

        End Sub

        ''' <summary>
        ''' Odeslat e-mail bez přílohy.
        ''' </summary>
        ''' <remarks></remarks>
        Sub OdeslatEmailAutoSMTP(ByVal sOdesilatel As String, ByVal sPrijemce As String, ByVal sPredmet As String, ByVal sZprava As String)

            Dim Mail As New System.Net.Mail.MailMessage(sOdesilatel, sPrijemce, sPredmet, _
                                                        "<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">" & _
                                                        "<style>body {font-family: Arial CE, sans-serif;font-size:12px;line-height:23px;} .GreenBox {padding:15px;padding-bottom:10px;padding-top:5px;background-color:#e5f5e3;border:1px solid #aed4a9;} .Caption {font-size:16px;line-height:27px;}</style></head><body>" & _
                                                        sZprava & "</body></html>")

            Mail.IsBodyHtml = True
            Mail.BodyEncoding = Encoding.UTF8

			Dim mySmtp As New Net.Mail.SmtpClient("mail.pcsolution.cz")
			Dim credential As New System.Net.NetworkCredential("soukup@pcsolution.cz", "Galvanometr123")
			mySmtp.Credentials = credential
            mySmtp.Port = 25

            Try
                mySmtp.Send(Mail)
            Catch ex As Exception
				'MsgBox(ex.ToString)
			End Try

            'HttpContext.Current.Response.Write(ex.ToString)

        End Sub

        ''' <summary>
        ''' Odeslat e-mail s přílohou.
        ''' </summary>
        ''' <remarks></remarks>
        Sub OdeslatEmailPriloha(ByVal sOdesilatel As String, ByVal sPrijemce As String, ByVal sPredmet As String, _
                                ByVal sZprava As String, ByVal filePriloha As RadAsyncUpload)

            Dim Mail As New System.Net.Mail.MailMessage(sOdesilatel, sPrijemce, sPredmet, _
                                                        "<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">" & _
                                                        "</head><body><span style=""font-family: Arial CE, sans-serif;font-size:12px;"">" & _
                                                        sZprava & "</span></body></html>")


            Mail.IsBodyHtml = True
            Mail.BodyEncoding = Encoding.UTF8

            Try
                If filePriloha.UploadedFiles.Count = 0 Then
                Else
                    For n As Int16 = 0 To filePriloha.UploadedFiles.Count - 1

                        Dim sPriloha As String = "A" & Guid.NewGuid.ToString
                        Directory.CreateDirectory(_PathFoto & "\Temp\" & sPriloha)
                        filePriloha.UploadedFiles(n).SaveAs(_PathFoto & "\Temp\" & sPriloha & "\" & _
                                                      System.IO.Path.GetFileName(filePriloha.UploadedFiles(n).FileName))
                        Mail.Attachments.Add(New System.Net.Mail.Attachment(_PathFoto & "\Temp\" & sPriloha & "\" & _
                                                                            System.IO.Path.GetFileName(filePriloha.UploadedFiles(n).FileName)))
                    Next
                End If
            Catch ex As Exception
                Mail.Body &= ""
                'Mail.Body &= "CHYBA: " & ex.ToString & "<br/>" & HttpContext.Current.Application("uploadAdr") & "\Adresar\" & System.IO.Path.GetFileName(filePriloha.PostedFile.FileName)
            End Try

            Dim mySmtp As New Net.Mail.SmtpClient("send.pcsolution.cz")
			Dim credential As New System.Net.NetworkCredential("smtp@pcsolution.cz", "galvanometr")
			mySmtp.Credentials = credential
			mySmtp.Port = 25

			Try
				mySmtp.Send(Mail)
			Catch ex As Exception
                'HttpContext.Current.Response.Write(ex.ToString)
            End Try

		End Sub

        ''' <summary>
        ''' Odeslat e-mail s přílohou.
        ''' </summary>
        ''' <remarks></remarks>
        Sub OdeslatEmailPriloha(ByVal sOdesilatel As String, ByVal sPrijemce As String, ByVal sPredmet As String,
						 ByVal sZprava As String, ByVal sPath As String, sPath2 As String, sPath3 As String)

			Dim Mail As New System.Net.Mail.MailMessage(sOdesilatel, sPrijemce, sPredmet,
														"<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">" &
														"</head><body><span style=""font-family: Arial CE, sans-serif;font-size:12px;"">" &
														sZprava & "</span></body></html>")


			Mail.IsBodyHtml = True
			Mail.BodyEncoding = Encoding.UTF8

			If sPath <> "" Then
				Mail.Attachments.Add(New System.Net.Mail.Attachment(sPath))
			End If
			If sPath2 <> "" Then
				Mail.Attachments.Add(New System.Net.Mail.Attachment(sPath2))
			End If
			If sPath3 <> "" Then
				Mail.Attachments.Add(New System.Net.Mail.Attachment(sPath3))
			End If

			Dim mySmtp As New Net.Mail.SmtpClient("send.pcsolution.cz")
			Dim credential As New System.Net.NetworkCredential("smtp@pcsolution.cz", "galvanometr")
			mySmtp.Credentials = credential
            mySmtp.Port = 25

            Try
                mySmtp.Send(Mail)
            Catch ex As Exception
                'HttpContext.Current.Response.Write(ex.ToString)
            End Try

        End Sub


    End Module

End Namespace
