Hi, In a web application in VS2005, I am facing a problem. In this, an email is sent through a service. Earlier, the application was in VS2003. Then there was no problem. But when it is converted to 2005, it is not being sent. The error in the log file is
" System.FormatException: An invalid character was found in header name.
at System.Net.Mime.MailBnfHelper.ValidateHeaderName(String data)
at System.Net.Mime.HeaderCollection.Add(String name, String value)
at cDWMain.cDWBusTier.cDWRouting.send_email_WithMaxEmailSize(String emailAddr, String DocPath, String RouteID, Int32 intMaxEmailSize, Int64 DocID, String FromUserEmail)"
Hi, In a web application in VS2005, I am facing a problem. In this, an email is sent through a service. Earlier, the application was in VS2003. Then there was no problem. But when it is converted to 2005, it is not being sent. The error in the log file is
" System.FormatException: An invalid character was found in header name.
at System.Net.Mime.MailBnfHelper.ValidateHeaderName(String data)
at System.Net.Mime.HeaderCollection.Add(String name, String value)
at cDWMain.cDWBusTier.cDWRouting.send_email_WithMaxEmailSize(String emailAddr, String DocPath, String RouteID, Int32 intMaxEmailSize, Int64 DocID, String FromUserEmail)"
Plz do click "Mark as Answer" on the post that helped you. This will also give you point and help readers to know which post solved your issue and make their search easy.
It has nothing do with encoding.. First check for proper Namespace. In VS2003 it was System.Web.Mail and in VS2005 is .Net. Check for all these and aslo port then also if you are not able to send then it might be the problem with Encoding. Please post your
code that you are using.
Private
Function SendEmail(ByVal EmailAddressList
As
String,
ByVal DocPath
As
String,
ByVal RouteDetails
As DataRowView,
Optional
ByVal DocID
As
Long = 0)
As
Boolean
Try
'On Error GoTo errorHandle
Dim myMail
As
New System.Net.Mail.MailMessageDim myServ
As
New System.Net.Mail.SmtpClient(mMailServer)Dim objdoc
As
New cDWBusTier.cDWDocument(Me.mObjBus)Dim
mEmailFooter As
String = _"<table width=""50%"" border=""0"" ID=""Table3"">"
& _"<tr bgcolor=""white"">" & _"<td style=""FONT-SIZE: 8pt""></td>"
& _"</tr>" & _"</table>"
Dim myAttach
As
New System.Net.Mail.Attachment(DocPath)Catch ex
As Exception"MAIL SERVER : " & myServ.Host &
" cDwRouting :: send_email - Doc ID : " & DocIDWhile
Not (ex.InnerException
Is
Nothing)" The following InnerException reported: " + ex.InnerException.ToString())End
While
Return
False
End
Try
End
If
myMail.To.Add(EmailAddressList)
If IsDBNull(RouteDetails("FromUserEmail"))
OrElse Len(RouteDetails("FromUserEmail")) = 0
Then
myMail.From =
New Net.Mail.MailAddress("info@docwize.com")Else
myMail.From =
New Net.Mail.MailAddress(RouteDetails("FromUserEmail"))End
If
"http://schemas.microsoft.com/cdo/configuration/smtpserverport", mMailServerPort)End
If
'************************************************
If mMailSMTPAuthenticate
Then
'Dim sclnt As New System.Net.Mail.SmtpClient
'sclnt.Credentials = New System.Net.NetworkCredential(mMailSMTPUsername, mMailSMTPPassword)
myMail.Headers.Add(
myMail.Headers.Add(
myMail.Headers.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1")"http://schemas.microsoft.com/cdo/configuration/sendusername",
mMailSMTPUsername)"http://schemas.microsoft.com/cdo/configuration/sendpassword", mMailSMTPPassword)End
If
Try
myServ.Send(myMail)
Return
True
mError =
mError = mError & (
mSendMailError = ex.InnerException.ToString
ex = ex.InnerException
Catch ex
As Exception"MAIL SERVER : " & myServ.Host &
" cDwRouting :: send_email - Doc ID : " & DocIDWhile
Not (ex.InnerException
Is
Nothing)" The following InnerException reported: " + ex.InnerException.ToString())End
While
Return
False
End
Try
Else
mError =
mError = mError &
"MAIL SERVER : " & myServ.Host &
" cDwRouting :: send_email - Doc ID : " & DocID" - No Recipient Email Address"
suryaacd
Member
108 Points
286 Posts
Email not being sent
Nov 13, 2009 04:37 AM|LINK
Hi, In a web application in VS2005, I am facing a problem. In this, an email is sent through a service. Earlier, the application was in VS2003. Then there was no problem. But when it is converted to 2005, it is not being sent. The error in the log file is " System.FormatException: An invalid character was found in header name.
at System.Net.Mime.MailBnfHelper.ValidateHeaderName(String data)
at System.Net.Mime.HeaderCollection.Add(String name, String value)
at cDWMain.cDWBusTier.cDWRouting.send_email_WithMaxEmailSize(String emailAddr, String DocPath, String RouteID, Int32 intMaxEmailSize, Int64 DocID, String FromUserEmail)"
Can anyone help me. Thanks in advance.
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: Email not being sent
Nov 13, 2009 08:15 AM|LINK
Hi,
have u tried specifying the port..
if UR trying to Send mail using Gmail U have Specify the port number..
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
venkatu2005
All-Star
32487 Points
6742 Posts
Re: Email not being sent
Nov 13, 2009 08:26 AM|LINK
Check code for sending Email
Thanks.
suryaacd
Member
108 Points
286 Posts
Re: Email not being sent
Nov 13, 2009 09:04 AM|LINK
Hi, It is specified like this
If
mMailServerPort <> 25 ThenmyMail.Headers.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpserverport", mMailServerPort)End If
dilipdiyewar
Member
258 Points
42 Posts
Re: Email not being sent
Nov 13, 2009 09:34 AM|LINK
Imports System.Net.Mail
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _ Net.NetworkCredential("username", "password")
SmtpServer.Port = 25
SmtpServer.Host = "smtpout.secureserver.net"
mail = New MailMessage()
mail.From = New MailAddress("fromuser")
mail.To.Add("touser") mail.Subject = "windows service"
mail.Body = "windows service"
SmtpServer.Send(mail)
nimish_soft
Contributor
2419 Points
459 Posts
Re: Email not being sent
Nov 13, 2009 09:40 AM|LINK
try the code
http://nimishgarg.blogspot.com/2009/10/sendmail-with-attachments.html
Software Developer
IndiaMART InterMESH Limited, Noida
For Free ASP.NET & Oracle Code Snippets
Follow: http://nimishgarg.blogspot.com/
Plz do click "Mark as Answer" on the post that helped you. This will also give you point and help readers to know which post solved your issue and make their search easy.
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: Email not being sent
Nov 13, 2009 09:45 AM|LINK
Seems Ur using some differnt smtp Server to Put UR mail
Try verify the port number of That SMTP server
OR
try some othrway of sending mail
http://www.aspcode.net/Send-mail-from-ASPNET-using-your-gmail-account.aspx
http://www.codeproject.com/KB/aspnet/smtp_mail.aspx
http://www.codeproject.com/KB/aspnet/EmailApplication.aspx
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
suryaacd
Member
108 Points
286 Posts
Re: Email not being sent
Nov 26, 2009 07:26 AM|LINK
Does this have anything to do with encoding? Please help
ramya.he
Member
15 Points
10 Posts
Re: Email not being sent
Nov 26, 2009 10:37 AM|LINK
It has nothing do with encoding.. First check for proper Namespace. In VS2003 it was System.Web.Mail and in VS2005 is .Net. Check for all these and aslo port then also if you are not able to send then it might be the problem with Encoding. Please post your code that you are using.
suryaacd
Member
108 Points
286 Posts
Re: Email not being sent
Nov 26, 2009 10:57 AM|LINK
Private Function SendEmail(ByVal EmailAddressList As String, ByVal DocPath As String, ByVal RouteDetails As DataRowView, Optional ByVal DocID As Long = 0) As Boolean
Try
'On Error GoTo errorHandle
Dim myMail As New System.Net.Mail.MailMessageDim myServ As New System.Net.Mail.SmtpClient(mMailServer)Dim objdoc As New cDWBusTier.cDWDocument(Me.mObjBus)Dim mEmailFooter As String = _"<table width=""50%"" border=""0"" ID=""Table3"">" & _"<tr bgcolor=""white"">" & _"<td style=""FONT-SIZE: 8pt""></td>" & _"</tr>" & _"</table>"
If EmailAddressList <> "" Then
'Get_Routing(RouteID)myMail.IsBodyHtml =
True
Dim mRoutingBody As StringmRoutingBody =
"<table width=""50%"" border=""0"" ID=""Table1"">" & _"<tr bgcolor=""#0000ff"">" & _"<td><font color=""#ffffff"" size=""-1"" face=""Tahoma"">Instruction Details</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Due Date:</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" & Catchnull(RouteDetails("Action_Request_Date"), "") & "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Description:</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" & RouteDetails("Action_Request_Notes") & "</font></td>" & _"</tr>" & _"</table>"
'myMail.Body = "Action Request Notes :" + Chr(10) + Chr(13) + tempDs.Tables(0).Rows(0).Item("Action_Request_Notes")myMail.Body = mRoutingBody
If DocID <> 0 Thenobjdoc.Doc_ID = DocID
If objdoc.GetDocument() Then
Dim strHTMLFooter2 As String
'strHTMLFooter2 = "<tr><td><font size=""-1"" face=""Tahoma"">Go to <a href=""" & Me.mObjBus.URL & "mylogin.aspx"">DocWize</a> to access your Docwize Inbox</font></td></tr></table>"strHTMLFooter2 =
"<tr><td> </td></tr></table>"
Dim objTasks1 As New cDWTasks(Me.mObjBus)If objTasks1.Get_Task(objdoc.Doc_ID) = True Then
End If
If objdoc.DocType <> "Task" Then
Dim mDocumentBody As String = "<table width=""50%"" border=""0"" >" & _"<tr bgcolor=""#0000FF"">" & _"<td colspan=2 ><font color=""#FFFFFF"" size=""-1"" face=""Tahoma"">Document Details</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Description :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" + objdoc.Description() + "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Type :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" + objdoc.DocType() + "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Document No :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" + objdoc.Doc_Number() + "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Due Date :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma""> " + objTasks1.Action_Request_Date + "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Diarised Date :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma""> " + objTasks1.Diarisedate + "</font></td>" & _"</tr>" & _"</table>"myMail.Body = myMail.Body + mDocumentBody + strHTMLFooter2 + mEmailFooter
Else
Dim objTasks As New cDWTasks(Me.mObjBus)If objTasks.Get_Task(objdoc.Doc_ID) = True Then
Dim mTaskBody As String = "<table width=""50%"" border=""0"" >" & _"<tr bgcolor=""#0000FF"">" & _"<td colspan=2 ><font color=""#FFFFFF"" size=""-1"" face=""Tahoma"">DocWize Task</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Task subject :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" + objdoc.Description() + "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Task details :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" + objTasks.Task_Details + "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Due Date :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" + objTasks.Action_Request_Date + "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Type :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" + objTasks.TaskType + "</font></td>" & _"</tr>" & _"<tr>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">Diarised Date :</font></td>" & _"<td style=""border-top:1px solid #D5E1EA; border-bottom:1px solid #D5E1EA; border-left:1px solid #DAE9F2 ; border-right:1px solid #83B5D4""><font size=""-1"" face=""Tahoma"">" + objTasks.Diarisedate + "</font></td>" & _"</tr>" & _"</table>"myMail.Body = myMail.Body + mTaskBody + strHTMLFooter2 + mEmailFooter
ElsemyMail.Body = myMail.Body + mEmailFooter
End IfobjTasks.Dispose()
End If
End If
End If
If DocPath <> "" Then
TrymyMail.Attachments.Add(myAttach)
mError =
mError = mError & (
ex = ex.InnerException
Dim myAttach As New System.Net.Mail.Attachment(DocPath)Catch ex As Exception"MAIL SERVER : " & myServ.Host & " cDwRouting :: send_email - Doc ID : " & DocIDWhile Not (ex.InnerException Is Nothing)" The following InnerException reported: " + ex.InnerException.ToString())End While
Return False
End Try
End IfmyMail.To.Add(EmailAddressList)
If IsDBNull(RouteDetails("FromUserEmail")) OrElse Len(RouteDetails("FromUserEmail")) = 0 ThenmyMail.From =
New Net.Mail.MailAddress("info@docwize.com")ElsemyMail.From =
New Net.Mail.MailAddress(RouteDetails("FromUserEmail"))End IfmyMail.Subject = RouteDetails(
"Action_Request") & " : " & RouteDetails("Action_Subject") & " - " & mObjBus.Company_Login & ", Docwize"
'check if we are using the defualt port
If mMailServerPort <> 25 ThenmyMail.Headers.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpserverport", mMailServerPort)End If
'************************************************
If mMailSMTPAuthenticate Then
'Dim sclnt As New System.Net.Mail.SmtpClient
'sclnt.Credentials = New System.Net.NetworkCredential(mMailSMTPUsername, mMailSMTPPassword)myMail.Headers.Add(
myMail.Headers.Add(
myMail.Headers.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")"http://schemas.microsoft.com/cdo/configuration/sendusername", mMailSMTPUsername)"http://schemas.microsoft.com/cdo/configuration/sendpassword", mMailSMTPPassword)End If
TrymyServ.Send(myMail)
Return TruemError =
mError = mError & (
mSendMailError = ex.InnerException.ToString
ex = ex.InnerException
Catch ex As Exception"MAIL SERVER : " & myServ.Host & " cDwRouting :: send_email - Doc ID : " & DocIDWhile Not (ex.InnerException Is Nothing)" The following InnerException reported: " + ex.InnerException.ToString())End While
Return False
End Try
ElsemError =
mError = mError &
"MAIL SERVER : " & myServ.Host & " cDwRouting :: send_email - Doc ID : " & DocID" - No Recipient Email Address"
Return False
End IfmError = e.ToString
LogError(e.ToString)
Catch e As ExceptionEnd Try
'Exit Function
'errorHandle:
' Me.mError = Err.Description & "MailServer = " & Me.mMailServer & " - cDwRouting :: send_email - RID = " & RouteID & " - DOCID : " & DocID & " - Err.Number = " & Err.Number
' Return False
End FunctionIt is System.Net.Mail and the port is 25.Please see the code. Thanks in advance.