Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

E-mail alignment Problem in vb.net

Posted on 2008-06-09
17
Medium Priority
?
393 Views
Last Modified: 2013-11-26
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
Comment
Question by:mahmood66
  • 9
  • 8
17 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 21748859
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
 

Author Comment

by:mahmood66
ID: 21756800
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 21757225
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:mahmood66
ID: 21757290
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 21757311
mail.BodyFormat = MailFormat.Html
Mailmsg.Body = "<HTML><HEAD></HEAD><BODY><p><font face='Courier'>" + Mailbody + "</font></p></BODY></HTML>"
0
 

Author Comment

by:mahmood66
ID: 21757363
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 21757393
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
 

Author Comment

by:mahmood66
ID: 21766883
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 21766929
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
 

Author Comment

by:mahmood66
ID: 21766952
there is no special sign, i am displaying the plain text as i have sent you one image also.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 1000 total points
ID: 21766962
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
 

Author Comment

by:mahmood66
ID: 21766991
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 21767045
In the code above, where do you get an error ? Or what is the problem that you still have ?
0
 

Author Comment

by:mahmood66
ID: 21767179
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 21767205
To show the border around your table:
 HTML = "<table Border=2 CellPadding=10 CellSpacing=10>" & vbCrLf

Which title do you mean ?
0
 

Author Comment

by:mahmood66
ID: 21767228
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 21767323
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question