Re: strange problem with smtpmail



i narrowed it a bit down

Note that remote server is a BLS server ( not a web server ) but a windows
service wich starts dll`s through reflection

If i copy a test project ( exe ) to this server and run in the same user
context as the service is running , everything works as expected , but if
the service invokes the method (through interfacing and reflection ) the
e-mails are send but arrive as HTML source instead of formatted HTML

So the problem must be in the combination Reflection and SMTP class

( for the time beeing i send my mails from this service now as plain text ,
wich works fine )

but i wonder why it wil not work with HTML formatting

Michel








"Cor Ligthert [MVP]" wrote:

Michel,

You most probably make Herfried happy.

Try (UrlEncode (From))

etc

:-)

Cor





"Michel Posseth [MCP]" <MichelPossethMCP@xxxxxxxxxxxxxxxxxxxxxxxxx> schreef
in bericht news:B94734F4-EDF8-43CD-966A-0469F41C520F@xxxxxxxxxxxxxxxx
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,
"NePros@xxxxxxxxxxxxxxxx", 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













.



Relevant Pages

  • Re: Need Help | Rolling out new App. | Trouble with some computers
    ... Server as the back end. ... Option Compare Database ... Dim varReturn As Variant ... Dim lngAuth As Long, strDept As String, strFirst As String, strLast ...
    (microsoft.public.access.modulesdaovba)
  • Re: Desperately need help to setup with asp net !!
    ... must be done by the Vb.net application on the server. ... What I have hard time to implement is passing data from the browser to ... Dim strConnection As String ... Dim con As New Data.SqlClient.SqlConnection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Best way to communicate from Desktop to SQL DB
    ... the remote SQL Server, in other words, how do I create a connection string ... to a remote server. ... Dim cmd As New SqlCommand ... Dim ProductID As Integer = CType, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Desperately need help to setup with asp net !!
    ... must be done by the Vb.net application on the server. ... What I have hard time to implement is passing data from the browser to ... Dim strConnection As String ... Dim con As New Data.SqlClient.SqlConnection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Using Visual Basic NET to Access Terminal Services Session and Client Information
    ... It also accesses the Client Information for the client which executes this program on a Terminal Services Server. ... Dim pWinStationName As String ' integer LPTSTR - Pointer to a null-terminated string containing the name of the WinStation for this session ...
    (microsoft.public.windows.terminal_services)