Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

E-mail alignment Problem in vb.net

i have written the code in vb.net to generate the automated e-mail, and i m successful to generate the mail and to get the proper data, the only problem is my data which is in Column 's form is not properly aligning, even i use the following query to mention the specifict width fo each column, even in vb.net i use string.PadLeft and string. PadRight function also, it is still not aligning, for your reference i am attaching screen short.

Following query i m applying, see am mentioning proper width for each column
SELECT     cast(containerno as  char(15)) as Containerno,
cast(cast( DATEDIFF([Day], issuedate, GETDATE()) as char(3)) as int)  AS LoadedDays,
cast(rtrim(Ltrim(pod_small)) as char(3)) as POD,
cast(vessel_d as char(15)) as Vessel,
eta_d,
--cast(rem1 as char(16)) as Remarks,
dsagent
FROM         dbo.GIN_VIEW
WHERE     (eta_d <= GETDATE()) AND (Doc_Copy IS NULL)

E-mail-Output-Alignment-Error.JPG
0
mahmood66
Asked:
mahmood66
  • 9
  • 8
1 Solution
 
DhaestCommented:
What font-type do you use in  your email ?
If you use fe courier, then all the characters will take the same space. So the space for a L is the same as l. If you have arial, the characters will only take the place they need. If so, then you get what you have now !
0
 
mahmood66Author Commented:
you are 100% right.
how can i change the font in vb.net

this is my code, where i should which code, becuase fontstyle property i m not getting.

If rbtnBLDraft.Checked = True Then
            Dim strSql As String
            Dim ObjDAMail As New SqlDataAdapter
            Dim ObjDSMail As New DataSet
            Dim Mailbody As String

            gettoday()
            strSql = ""

            strSql = "select * from view_emailBLDraft where dsagent ='" & cmbAgent.Text & "' order by LoadedDays desc"

            'Set the properties
            ObjDAMail.SelectCommand = New SqlCommand
            ObjDAMail.SelectCommand.CommandText = strSql
            ObjDAMail.SelectCommand.Connection = Con

            ObjDAMail.Fill(ObjDSMail, "WeightMaster")

            If ObjDSMail.Tables(0).Rows.Count = 0 Then
                MsgBox("Not Record Found for E-mail")
                Exit Sub
            End If

            obj.SmtpServer = "192.168.0.110"
            'Multiple recepients can be specified using ; as the delimeter
            'Mailmsg.To = "it.mr@sharifmetals.com"
            Mailmsg.To = txtEMail.Text
            ' Mailmsg.Cc = "it.mq@sharifmetals.com"
            Mailmsg.From = "\it.mr@sharifmetals.com\ <it@sharifmetals.com>"



            'Specify the body format

            Mailmsg.BodyFormat = MailFormat.Text     'Send the mail in HTML Format


            'If you want you can add a reply to header
            'Mailmsg.Headers.Add("Reply-To", "Manoj@geinetech.net")
            'custom headersare added like this
            'Mailmsg.Headers.Add("Manoj", "TestHeader")

            Mailmsg.Subject = " Draft Copies Still Awaited "
            Mailbody = "M/s: " & cmbAgent.Text & Environment.NewLine & Environment.NewLine

            Mailbody += "Dear Sir, " & Environment.NewLine & " From our recors, we found that draft B/L copies for below shipments are still awaited " & Environment.NewLine & Environment.NewLine

            Dim c As Int16
           


            Mailbody += "---------------------------------------------------------------------------" & Environment.NewLine
            Mailbody += "Sr    ContainerNo   Loaded POD  Vessel          Vessel    Remarks" & Environment.NewLine
            Mailbody += "No.                 Days         Name            ETD" & Environment.NewLine
            Mailbody += "---------------------------------------------------------------------------" & Environment.NewLine

            With ObjDSMail.Tables(0)
                For c = 0 To .Rows.Count - 1
                    Mailbody += "|" & c + 1 & "| " & CType(.Rows(c).Item(0), String).PadRight(20) & "| " & .Rows(c).Item(1) & " | " & .Rows(c).Item(2) & "| " & .Rows(c).Item(3) & "| " & .Rows(c).Item(4) & "|" & Environment.NewLine
                Next

            End With
           

            Mailbody += "---------------------------------------------------------------------------" & Environment.NewLine & Environment.NewLine
            Mailbody += Environment.NewLine & Environment.NewLine & "Kindly revert with draft BL copies for  all above containers or revert incase of any changes in vessel details." & Environment.NewLine & Environment.NewLine
            Mailbody += "Thanks & best regards" & Environment.NewLine
            Mailbody += "Shipping Dept."
            Mailmsg.Body = Mailbody

            obj.Send(Mailmsg)
0
 
DhaestCommented:
You'll need a html-mail

The Body property of the MailMessage instance would be in the HTML code as given in the following example.

Mailmsg.Body = <HTML><HEAD></HEAD><BODY><p><font face='Courier'>" + Mailbody + </font></p></BODY></HTML>

obj.Send(Mailmsg)
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
mahmood66Author Commented:
my application is windows based applicatin( code in vb.net) not web based application.
may be you have given in code for web based application. this given code is not working in my code. its given error. vb.net windows based application cannot read this systax.
0
 
DhaestCommented:
mail.BodyFormat = MailFormat.Html
Mailmsg.Body = "<HTML><HEAD></HEAD><BODY><p><font face='Courier'>" + Mailbody + "</font></p></BODY></HTML>"
0
 
mahmood66Author Commented:
in this given code, my "Environment.newline" isnot working and "vbtab" also not working the whole all output is comming in one sequence.

my output is given below. thanx in advance for your quick response.

M/s: ABSA - DAMMAM Dear Sir, From our recors, we found that draft B/L copies for below shipments are still awaited --------------------------------------------------------------------------- Sr ContainerNo Loaded POD Vessel Vessel Remarks No. Days Name ETD --------------------------------------------------------------------------- |1| HDMU 2585848| 44 | MNL| INTRA BHUM | 08/Jun/08| |2| HDMU 2585874| 44 | MNL| INTRA BHUM | 08/Jun/08| |3| HDMU 2561867| 42 | MNL| INTRA BHUM | 08/Jun/08| |4| FCIU 3219137| 38 | MNL| TBA | 25/May/08| |5| HJCU 8117547| 36 | HUZ| DA JI | 03/Jun/08| |6| FCIU 3509305| 36 | MNL| INTRA BHUM | 08/Jun/08| |7| TRLU 3904380| 32 | HUZ| DA JI | 03/Jun/08| |8| FSCU 6844944| 23 | XGA| TBA | 28/May/08| |9| HDMU 6222795| 7 | TAC| HARI BHUM | 13/Apr/08| --------------------------------------------------------------------------- Kindly revert with draft BL copies for all above containers or revert incase of any changes in vessel details. Thanks & best regards Shipping Dept.

environment.newline and vbtab only work in  Mailmsg.BodyFormat = MailFormat.Text,
i am waiting for you expert opinion.
0
 
DhaestCommented:
Because you need everything in html, you'll need to change the special signs
vbcrlf will be <br>
tab will be &nbsp;

You can also format your output as an html-table

http://www.motobit.com/tips/detpg_rshtml/
0
 
mahmood66Author Commented:
see the following code, only the last line of the code  Response.Write HTML is giving error, please help me out  in this. may be vb.net is not recognizing this code.
Dim HTML
  HTML = "<table CellPadding=0 CellSpacing=0>" & vbCrLf
  Do While Not RS.EOF
    HTML = HTML & "<TR>"
    HTML = HTML & "<TD>" & RS("IntCol") & "</TD>"
    HTML = HTML & "<TD>" & RS("CharCol") & "</TD>"
    HTML = HTML & "<TD>" & RS("VarCharCol") & "</TD>"
    HTML = HTML & "<TD>" & RS("MoneyCol") & "</TD>"
    HTML = HTML & "</TR>" & vbCrLf
    RS.MoveNext
  Loop
  HTML = HTML & "</table>" & vbCrLf
Response.Write HTML
0
 
DhaestCommented:
I see 2 possible problems.
1. Dim HTML as string
2. Are there special signs in your recordset or is it only plain text ?
0
 
mahmood66Author Commented:
there is no special sign, i am displaying the plain text as i have sent you one image also.
0
 
DhaestCommented:
I just tested this below and it worked for me
Dim HTML as string
  HTML = "<table CellPadding=0 CellSpacing=0>" & vbCrLf
    HTML = HTML & "<TR>"
    HTML = HTML & "<TD>" & "1" & "</TD>"
    HTML = HTML & "<TD>" & "2" & "</TD>"
    HTML = HTML & "<TD>" & "3" & "</TD>"
    HTML = HTML & "<TD>" & "4" & "</TD>"
    HTML = HTML & "</TR>" & vbCrLf
  HTML = HTML & "</table>" & vbCrLf
Response.Write (HTML)

Open in new window

0
 
mahmood66Author Commented:
data is coming correctly, but only problem with alignment, please lets have a look. now as you suggent me i am using html code. but here Response.write is giving error.  i am waiting for your reply, much thanx in advance.

If rbtnBLDraft.Checked = True Then
            Dim strSql As String
            Dim ObjDAMail As New SqlDataAdapter
            Dim ObjDSMail As New DataSet
            Dim Mailbody As String

            gettoday()
            strSql = ""

            strSql = "select * from view_emailBLDraft where dsagent ='" & cmbAgent.Text & "' order by LoadedDays desc"

            'Set the properties
            ObjDAMail.SelectCommand = New SqlCommand
            ObjDAMail.SelectCommand.CommandText = strSql
            ObjDAMail.SelectCommand.Connection = Con

            ObjDAMail.Fill(ObjDSMail, "WeightMaster")

            If ObjDSMail.Tables(0).Rows.Count = 0 Then
                MsgBox("Not Record Found for E-mail")
                Exit Sub
            End If

            obj.SmtpServer = "192.168.0.110"
            'Multiple recepients can be specified using ; as the delimeter
            'Mailmsg.To = "it.mr@sharifmetals.com"
            Mailmsg.To = txtEMail.Text
            ' Mailmsg.Cc = "it.mq@sharifmetals.com"
            Mailmsg.From = "\it.mr@sharifmetals.com\ <it@sharifmetals.com>"


            'Specify the body format

            Mailmsg.BodyFormat = MailFormat.Text     'Send the mail in HTML Format


            'If you want you can add a reply to header
            'Mailmsg.Headers.Add("Reply-To", "Manoj@geinetech.net")
            'custom headersare added like this
            'Mailmsg.Headers.Add("Manoj", "TestHeader")

            Mailmsg.Subject = " Draft Copies Still Awaited "
            Mailbody = "M/s: " & cmbAgent.Text & Environment.NewLine & Environment.NewLine

            Mailbody += "<HTML><HEAD></HEAD><BODY>" & "Dear Sir, " & Environment.NewLine & " From our recors, we found that draft B/L copies for below shipments are still awaited " & Environment.NewLine & Environment.NewLine & "<br></BODY></HTML>"

            Dim c As Int16
           


            Mailbody += "<HTML><HEAD></HEAD><BODY>" & "---------------------------------------------------------------------------" & Environment.NewLine & "<br></BODY></HTML>"

            Mailbody += "<HTML><HEAD></HEAD><BODY>" & "Sr    ContainerNo   Loaded POD  Vessel          Vessel    Remarks" & Environment.NewLine & "<br></BODY></HTML>"
            Mailbody += "<HTML><HEAD></HEAD><BODY>" & "No.                 Days         Name            ETD" & Environment.NewLine & "<br></BODY></HTML>"
            Mailbody += "<HTML><HEAD></HEAD><BODY>" & "---------------------------------------------------------------------------" & Environment.NewLine & "<br></BODY></HTML>"

            'With ObjDSMail.Tables(0)
            '    For c = 0 To .Rows.Count - 1
            '        Mailbody += "<HTML><HEAD></HEAD><BODY> <table CellPadding=0 CellSpacing=0> <TR> <TD>" & "|" & c + 1 & "| " & CType(Trim(.Rows(c).Item(0)), String).PadRight(15) & "| " & .Rows(c).Item(1) & " | " & .Rows(c).Item(2) & "| " & CType(Trim(.Rows(c).Item(3)), String).PadRight(15) & "| " & .Rows(c).Item(4) & "|" & Environment.NewLine & "<br></TD></TR></Table> </BODY></HTML>"
            '    Next

            'End With

            Dim HTML
            HTML = "<table CellPadding=10 CellSpacing=10>" & vbCrLf
            For c = 0 To ObjDSMail.Tables(0).Rows.Count - 1
                HTML = HTML & "<TR>"
                HTML = HTML & "<TD>" & ObjDSMail.Tables(0).Rows(c).Item(0) & "</TD>"
                HTML = HTML & "<TD>" & ObjDSMail.Tables(0).Rows(c).Item(1) & "</TD>"
                HTML = HTML & "<TD>" & ObjDSMail.Tables(0).Rows(c).Item(2) & "</TD>"
                HTML = HTML & "<TD>" & ObjDSMail.Tables(0).Rows(c).Item(3) & "</TD>"
                HTML = HTML & "</TR>" & vbCrLf
            Next
            HTML = HTML & "</table>" & vbCrLf
            Mailbody += "<HTML><HEAD></HEAD> <BODY>" & HTML & "</BODY></HTML>"

            Mailbody += "---------------------------------------------------------------------------" & Environment.NewLine & Environment.NewLine
            Mailbody += Environment.NewLine & Environment.NewLine & "Kindly revert with draft BL copies for  all above containers or revert incase of any changes in vessel details." & Environment.NewLine & Environment.NewLine
            Mailbody += "Thanks & best regards" & Environment.NewLine
            Mailbody += "Shipping Dept."
            Mailmsg.Body = Mailbody

            Mailmsg.BodyFormat = MailFormat.Html
            Mailmsg.Body = "<HTML><HEAD></HEAD><BODY><p><font face='Courier'>" + Mailbody + "</font></p></BODY></HTML>"

            obj.Send(Mailmsg)
0
 
DhaestCommented:
In the code above, where do you get an error ? Or what is the problem that you still have ?
0
 
mahmood66Author Commented:
hammmmmmmmmmmmmmm, Yes, now I have got my required allignments , a bundle of thanx
but now tell me how can i change the back color of  the title, and how can i put the line in the table,
I know that , now the data is displaying in table but table line are not displaying, how can i display the table line.
again budle of thanx again.
0
 
DhaestCommented:
To show the border around your table:
 HTML = "<table Border=2 CellPadding=10 CellSpacing=10>" & vbCrLf

Which title do you mean ?
0
 
mahmood66Author Commented:
following are the my title or headings of my table. i want to change the Backgroup color into gray.

HTML = "<table Border=2  table CellPadding=10 CellSpacing=10>" & vbCrLf
            HTML = HTML & "<TR>"
            HTML = HTML & "<TD> Container No  </TD>"
            HTML = HTML & "<TD>Loaded Days</TD>"
            HTML = HTML & "<TD>POD</TD>"
            HTML = HTML & "<TD>Vessel Name</TD>"
            HTML = HTML & "<TD>Vessel Date</TD>"
            HTML = HTML & "<TD>Remarks</TD>"
            HTML = HTML & "</TR>" & vbCrLf

please tell me any good book for asp.net.
at last i appricates the experts a lot.
0
 
DhaestCommented:
Put your header into a TH-tagging !

HTML = "<table Border=2  table CellPadding=10 CellSpacing=10>" & vbCrLf
            HTML = HTML & "<TR>"
            HTML = HTML & "<TH bgcolor=Gray> Container No  </TH>"
            HTML = HTML & "<TH bgcolor=Gray>Loaded Days</TH>"
            HTML = HTML & "<TH bgcolor=Gray>POD</TH>"
            HTML = HTML & "<TH bgcolor=Gray>Vessel Name</TH>"
            HTML = HTML & "<TH bgcolor=Gray>Vessel Date</TH>"
            HTML = HTML & "<TH bgcolor=Gray>Remarks</TH>"
            HTML = HTML & "</TR>" & vbCrLf

bgcolor=Gray
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now