M
Michel Posseth [MCP]
This is weird
i have a method :
Public Function SendMailMessage(ByVal Recipient As String, ByVal Body As
String, ByVal From As String, Optional ByVal BCC As String = "", Optional
ByVal CC As String = "", Optional ByVal Subject As String = "", Optional
ByVal IsBodyHtml As Boolean = True) As Boolean
Try
Dim mMailMessage As New MailMessage()
mMailMessage.From = New MailAddress(From)
mMailMessage.To.Add(New MailAddress(Recipient))
If Not String.IsNullOrEmpty(BCC) Then
mMailMessage.Bcc.Add(New MailAddress(BCC))
End If
If Not String.IsNullOrEmpty(CC) Then
mMailMessage.CC.Add(New MailAddress(CC))
End If
mMailMessage.Subject = Subject
mMailMessage.Body = Body
mMailMessage.IsBodyHtml = IsBodyHtml
mMailMessage.Priority = MailPriority.Normal
Dim mSmtpClient As New SmtpClient(My.Settings.SMTPHost,
My.Settings.SMTPPort)
mSmtpClient.Send(mMailMessage)
Catch ex As Exception
Return False
End Try
Return True
End Function
wich works perfect on a local system when sending e-mail in HTML format
however when the method is run in a server process the e-mails that i
receive loose there HTML markup
so short :
Local nice formated html message , remote running on unattended sewrver
process but method in the same dll with all the same settings mail arrives
as HTML source code
anyone an idea ??? what i am missing
here is the full source of the server process ( wich is started by a
service with reflection )
MAIL
Imports System.Text.RegularExpressions
Imports System.Net.Mail
Public Class EMail
Public Function ValidEMail(ByVal email As String) As Boolean
'ruwe controle dmv regex of een mail adres wel geldig kan zijn
Dim reg As New Regex("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}
\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)")
Return reg.IsMatch(email)
End Function
Public Function SendMailMessage(ByVal Recipient As String, ByVal Body As
String, ByVal From As String, Optional ByVal BCC As String = "", Optional
ByVal CC As String = "", Optional ByVal Subject As String = "", Optional
ByVal IsBodyHtml As Boolean = True) As Boolean
Try
Dim mMailMessage As New MailMessage()
mMailMessage.From = New MailAddress(From)
mMailMessage.To.Add(New MailAddress(Recipient))
If Not String.IsNullOrEmpty(BCC) Then
mMailMessage.Bcc.Add(New MailAddress(BCC))
End If
If Not String.IsNullOrEmpty(CC) Then
mMailMessage.CC.Add(New MailAddress(CC))
End If
mMailMessage.Subject = Subject
mMailMessage.Body = Body
mMailMessage.IsBodyHtml = IsBodyHtml
mMailMessage.Priority = MailPriority.Normal
Dim mSmtpClient As New SmtpClient(My.Settings.SMTPHost,
My.Settings.SMTPPort)
mSmtpClient.Send(mMailMessage)
Catch ex As Exception
Return False
End Try
Return True
End Function
End Class
Method that uses Mail class
Private Sub CreateXML()
SortByRadioMeter()
Dim _HTMWORowS As String = String.Empty
Dim sBodyHTML As String = My.Settings.HTMMail
sBodyHTML = sBodyHTML.Replace("#var:gebn#", Me.ProgNaam)
sBodyHTML = sBodyHTML.Replace("#var:start#", Date.Now.ToString)
Dim iCount As Integer = 0
Try
For Each Me._WONr In ParVals
If CancellProcess Then Exit Sub 'wanneer ontvangen dan
stoppen met verwerken
Try
Using clsRep As New clsReport(_WONr, Me.GebruikersNaam,
Me.ProgNaam, Me.PrinterId)
'events binden aan handler methods
AddHandler clsRep.ErrorOccured, AddressOf clsRepError
AddHandler clsRep.eSuccess, AddressOf clsRepeSuccess
'start genereren rapport
clsRep.CreateRep()
iCount += 1
_HTMWORowS = String.Concat(_HTMWORowS,
My.Settings.HTMWoRow.Replace("#var:wo#", _WONr.ToString), Environment.NewLine)
End Using
Catch ex As Exception
MyBase.RaiseError("W.O." & Environment.NewLine &
Environment.NewLine & ex.ToString & Environment.NewLine & " Values :
ObjectNr= " & _WONr.ToString & " User started =" & Me.GebruikersNaam)
End Try
Next
Catch ex As Exception
MyBase.RaiseProcessCancell("W.O. Print " & Environment.NewLine &
ex.ToString & Environment.NewLine & Environment.NewLine & " Values :
ObjectNr= " & _WONr.ToString & " User started =" & Me.GebruikersNaam)
Finally
sBodyHTML = sBodyHTML.Replace("#var:start#", Date.Now.ToString)
sBodyHTML = sBodyHTML.Replace("#var:body#", _HTMWORowS)
Try
Dim email As New ista.EMail
If email.ValidEMail(My.Settings.SendWoMail) Then
email.SendMailMessage(My.Settings.SendWoMail, sBodyHTML,
"(e-mail address removed)", My.Settings.SendWoMailBCC,
My.Settings.SendWoMailCC, String.Concat("W.O. Print ",
Date.Now.ToShortDateString, " aantal=", iCount.ToString), True)
End If
Catch ex As Exception
MyBase.RaiseError(ex.ToString)
End Try
End Try
End Sub
:-(
Michel
i have a method :
Public Function SendMailMessage(ByVal Recipient As String, ByVal Body As
String, ByVal From As String, Optional ByVal BCC As String = "", Optional
ByVal CC As String = "", Optional ByVal Subject As String = "", Optional
ByVal IsBodyHtml As Boolean = True) As Boolean
Try
Dim mMailMessage As New MailMessage()
mMailMessage.From = New MailAddress(From)
mMailMessage.To.Add(New MailAddress(Recipient))
If Not String.IsNullOrEmpty(BCC) Then
mMailMessage.Bcc.Add(New MailAddress(BCC))
End If
If Not String.IsNullOrEmpty(CC) Then
mMailMessage.CC.Add(New MailAddress(CC))
End If
mMailMessage.Subject = Subject
mMailMessage.Body = Body
mMailMessage.IsBodyHtml = IsBodyHtml
mMailMessage.Priority = MailPriority.Normal
Dim mSmtpClient As New SmtpClient(My.Settings.SMTPHost,
My.Settings.SMTPPort)
mSmtpClient.Send(mMailMessage)
Catch ex As Exception
Return False
End Try
Return True
End Function
wich works perfect on a local system when sending e-mail in HTML format
however when the method is run in a server process the e-mails that i
receive loose there HTML markup
so short :
Local nice formated html message , remote running on unattended sewrver
process but method in the same dll with all the same settings mail arrives
as HTML source code
anyone an idea ??? what i am missing
here is the full source of the server process ( wich is started by a
service with reflection )
Imports System.Text.RegularExpressions
Imports System.Net.Mail
Public Class EMail
Public Function ValidEMail(ByVal email As String) As Boolean
'ruwe controle dmv regex of een mail adres wel geldig kan zijn
Dim reg As New Regex("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}
\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)")
Return reg.IsMatch(email)
End Function
Public Function SendMailMessage(ByVal Recipient As String, ByVal Body As
String, ByVal From As String, Optional ByVal BCC As String = "", Optional
ByVal CC As String = "", Optional ByVal Subject As String = "", Optional
ByVal IsBodyHtml As Boolean = True) As Boolean
Try
Dim mMailMessage As New MailMessage()
mMailMessage.From = New MailAddress(From)
mMailMessage.To.Add(New MailAddress(Recipient))
If Not String.IsNullOrEmpty(BCC) Then
mMailMessage.Bcc.Add(New MailAddress(BCC))
End If
If Not String.IsNullOrEmpty(CC) Then
mMailMessage.CC.Add(New MailAddress(CC))
End If
mMailMessage.Subject = Subject
mMailMessage.Body = Body
mMailMessage.IsBodyHtml = IsBodyHtml
mMailMessage.Priority = MailPriority.Normal
Dim mSmtpClient As New SmtpClient(My.Settings.SMTPHost,
My.Settings.SMTPPort)
mSmtpClient.Send(mMailMessage)
Catch ex As Exception
Return False
End Try
Return True
End Function
End Class
Method that uses Mail class
Private Sub CreateXML()
SortByRadioMeter()
Dim _HTMWORowS As String = String.Empty
Dim sBodyHTML As String = My.Settings.HTMMail
sBodyHTML = sBodyHTML.Replace("#var:gebn#", Me.ProgNaam)
sBodyHTML = sBodyHTML.Replace("#var:start#", Date.Now.ToString)
Dim iCount As Integer = 0
Try
For Each Me._WONr In ParVals
If CancellProcess Then Exit Sub 'wanneer ontvangen dan
stoppen met verwerken
Try
Using clsRep As New clsReport(_WONr, Me.GebruikersNaam,
Me.ProgNaam, Me.PrinterId)
'events binden aan handler methods
AddHandler clsRep.ErrorOccured, AddressOf clsRepError
AddHandler clsRep.eSuccess, AddressOf clsRepeSuccess
'start genereren rapport
clsRep.CreateRep()
iCount += 1
_HTMWORowS = String.Concat(_HTMWORowS,
My.Settings.HTMWoRow.Replace("#var:wo#", _WONr.ToString), Environment.NewLine)
End Using
Catch ex As Exception
MyBase.RaiseError("W.O." & Environment.NewLine &
Environment.NewLine & ex.ToString & Environment.NewLine & " Values :
ObjectNr= " & _WONr.ToString & " User started =" & Me.GebruikersNaam)
End Try
Next
Catch ex As Exception
MyBase.RaiseProcessCancell("W.O. Print " & Environment.NewLine &
ex.ToString & Environment.NewLine & Environment.NewLine & " Values :
ObjectNr= " & _WONr.ToString & " User started =" & Me.GebruikersNaam)
Finally
sBodyHTML = sBodyHTML.Replace("#var:start#", Date.Now.ToString)
sBodyHTML = sBodyHTML.Replace("#var:body#", _HTMWORowS)
Try
Dim email As New ista.EMail
If email.ValidEMail(My.Settings.SendWoMail) Then
email.SendMailMessage(My.Settings.SendWoMail, sBodyHTML,
"(e-mail address removed)", My.Settings.SendWoMailBCC,
My.Settings.SendWoMailCC, String.Concat("W.O. Print ",
Date.Now.ToShortDateString, " aantal=", iCount.ToString), True)
End If
Catch ex As Exception
MyBase.RaiseError(ex.ToString)
End Try
End Try
End Sub
:-(
Michel