Colleagues,
Here's the function I've put together:
Here's the (error) message passed as parameter tcMsgText:
Note that there are vbCrLf's, and IsBodyHtml property's set to False.
This is what I get:
"ERROR OCCURED!
Could not find file 'FileMover_Manager'.
Occured in
mscorlib
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at FileMover_Manager.FileMover_Manager.MakeWorkersSubdirs(String pcTemplateDirName, String pcRootDir) in [Full path to]FileMover_Manager.vb:line 368 Program quits."
IOW, that last string, "Program quits." (in bold type), must be on the next line - but it is not: it's on the same line.
(BTW, the same happens when IsBodyHtml = True: CRLF's are ignored.)
What am I doing wrong?
Alternatively - what shall I do to force MailMessage to "obey" CrLf in the E-Mail message's body?
TIA!
Regards,
Ilya
Here's the function I've put together:
Code:
'===================================================================================================================================
Public Function SendEMail(ByVal tcSubjectLn As String, ByVal tcMsgText As String, ByVal tcSender As String, _
ByVal tcAddressee As String, ByVal tcSMTPSrvr As String) As Int16
'===================================================================================================================================
' Purpose : Sends E-Mail with the given subject line and text from the given sender to the given addressee(s).
' Description : Uses System.Net.Mail.MailMessage class.
' Parameters : Subject line, message text, Sender's E-Mail address, adressees E-Mail adresses list, SMTP Server name,
' All Mandatory, all Strings.
' Side effects : None.
' Notes : 1. Verbose on error if run in VS's IDE, silent otherwise.
' 2. No parameters' verification, presumed valid (errs if not, and then see p. 1).
'===================================================================================================================================
Dim loMail As New MailMessage(), loMailTo As New MailAddress(tcAddressee), loMailClient As New SmtpClient(tcSMTPSrvr, 25)
Dim lcLogStr As String = "", lnRet As Int16 = 0
loMail.To.Clear() 'Clear/Reset to: settings...
loMail.CC.Clear() 'Clear/Reset cc: settings...
loMail.Bcc.Clear() 'Clear/Reset bc: settings...
loMail.To.Add(loMailTo) 'Add override email value...
loMail.From = New MailAddress(tcSender)
loMail.Subject = tcSubjectLn 'Set the subject...
loMail.Body = tcMsgText 'Set the body...
loMail.IsBodyHtml = False ' True 'Set type to HTML...
'Send email...
Try
loMailClient.Send(loMail) 'Send the email...
Catch loErr As Exception
lnRet = -1
lcLogStr = lcLogStr & Now.ToString("yyyy-MM-dd HH:mm:ss") & ": ERROR OCCURED while sending E-Mail to " & tcAddressee & "!" & _
vbCrLf & Space(21) & loErr.Message & vbCrLf & Space(21) & "Occured in " & vbCrLf & Space(21) & loErr.Source & _
vbCrLf & Space(21) & loErr.StackTrace & vbCrLf & Space(21) & "E-Mail '" & tcSubjectLn & "' wasn't sent." & vbCrLf
Write2Log(gcLogFile, lcLogStr, True)
If glDevelop Then
MsgBox("ERROR OCCURED while sending E-Mail to" & tcAddressee & "!" & vbCrLf & loErr.Message & vbCrLf & "Occured in " & _
loErr.Source & vbCrLf & loErr.StackTrace, MsgBoxStyle.Critical, gcAppName)
End If
End Try
Return lnRet
End Function
'===================================================================================================================================
Here's the (error) message passed as parameter tcMsgText:
Code:
lcEMailMsg = "ERROR OCCURED!" & vbCrLf & loErr.Message & vbCrLf & "Occured in " & vbCrLf & loErr.Source & vbCrLf & _
loErr.StackTrace & vbCrLf & "Program quits." & vbCrLf
Note that there are vbCrLf's, and IsBodyHtml property's set to False.
This is what I get:
"ERROR OCCURED!
Could not find file 'FileMover_Manager'.
Occured in
mscorlib
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at FileMover_Manager.FileMover_Manager.MakeWorkersSubdirs(String pcTemplateDirName, String pcRootDir) in [Full path to]FileMover_Manager.vb:line 368 Program quits."
IOW, that last string, "Program quits." (in bold type), must be on the next line - but it is not: it's on the same line.
(BTW, the same happens when IsBodyHtml = True: CRLF's are ignored.)
What am I doing wrong?
Alternatively - what shall I do to force MailMessage to "obey" CrLf in the E-Mail message's body?
TIA!
Regards,
Ilya