Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public class SendMail
    {
        public int SendeMail(string company, string empcode, string fromaddress, string toaddress, string subject, string detail, string operation, string username)
        {
            Library lib = new Library();
            int sEmailSend = 0;
            try
            {
                MailMessage objMailMessage = new MailMessage();
                objMailMessage.To.Add(toaddress);
                objMailMessage.From = new MailAddress(fromaddress);
                objMailMessage.Subject = subject;
                objMailMessage.Body = "<center>";
                objMailMessage.Body +="<div>";
                objMailMessage.Body +="<table>";
                objMailMessage.Body+="<tr>";
                objMailMessage.Body+="<td>";
                objMailMessage.Body+="<u>SLIMITED<br/>";
                objMailMessage.Body+="RANAVAV</u>";
                objMailMessage.Body+="</td>";
                objMailMessage.Body+="</tr>";
                objMailMessage.Body+="</table>";
                objMailMessage.Body+="</div>";
                objMailMessage.Body += "</center>";
                objMailMessage.Body+="<br />";
                objMailMessage.Body += "<table>";
                objMailMessage.Body += "<tr >";
                objMailMessage.Body += "<td align="right" style="width: 600px">";
                objMailMessage.Body += "<asp:Label ID="lblEmpCode" CssClass="lbl" runat="server"  Width="113px">Employee No.</asp:Label>";
                objMailMessage.Body += "</td>";
                objMailMessage.Body += "<td  align="left" valign="top" style="width: 110px">";
                objMailMessage.Body += "<asp:Label ID="txtEmpCode" CssClass="lblBoldBlue"  runat="server">";
                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr>";
                objMailMessage.Body +="<td>";
                objMailMessage.Body +="To,<br/>";
                objMailMessage.Body +="Personal Department<br />";
                objMailMessage.Body +="SLimited<br />";
                objMailMessage.Body +="Rav";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";
                objMailMessage.Body +="<br /><br />";

                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr>";
                objMailMessage.Body +="<td>";
                objMailMessage.Body +="Dear Sir,";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";
                objMailMessage.Body +="<center>";
                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr>";
                objMailMessage.Body +="<td>";
                objMailMessage.Body +="Sub:<u>Application for Reimbursement of Medical Expenses</u>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";
                objMailMessage.Body +="</center>";
                objMailMessage.Body +="</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";
                objMailMessage.Body +="<br />";
                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr>";
                objMailMessage.Body +="<td>";
                objMailMessage.Body +="I,the undersigned,hereby certify that i have incurred an expense of Rs. <asp:TextBox ID="txtUserName" runat="server" MaxLength="10"></asp:TextBox><br />";
                objMailMessage.Body +="&nbsp;(Rupees<asp:TextBox ID="TextBox1" runat="server" MaxLength="10"></asp:TextBox>)towards Medical Expenses on Account of <br />";
                objMailMessage.Body +="my/self dependant family - members during the period from<asp:TextBox ID="TextBox2" runat="server" MaxLength="10"></asp:TextBox>to<asp:TextBox ID="TextBox3" runat="server" MaxLength="10"></asp:TextBox><br />";
                objMailMessage.Body +="and - request that the same may be reimbursed to me under the Company's Medical Benefit<br />";
                objMailMessage.Body +="Scheme.<br />";
                objMailMessage.Body +="<br />";
                objMailMessage.Body +="<br />";
                objMailMessage.Body +="<br />";
                objMailMessage.Body +="<br />";
                objMailMessage.Body +="Thanking you,";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table><br />";
                objMailMessage.Body +="<br />";
                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr>";
                objMailMessage.Body +="<td align="right" style="width: 491px">";
                objMailMessage.Body +="<asp:Label ID="lblsig" CssClass="lbl" runat="server"  Width="113px">Signature:</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="<td  align="left" valign="top" style="width: 188px">";
                objMailMessage.Body +="<asp:Label ID="txtsig" CssClass="lblBoldBlue"  runat="server">";
                objMailMessage.Body +="</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";
                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr >";
                objMailMessage.Body +="<td align="right" style="width: 491px">";
                objMailMessage.Body +="<asp:Label ID="lblname" CssClass="lbl" runat="server"  Width="113px">name:</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="<td  align="left" valign="top" style="width: 188px">";
                objMailMessage.Body +="<asp:Label ID="txtname" CssClass="lblBoldBlue"  runat="server">";
                objMailMessage.Body +="</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";
                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr >";
                objMailMessage.Body +="<td align="right" style="width: 491px">";
                objMailMessage.Body +="<asp:Label ID="lbldesignation" CssClass="lbl" runat="server"  Width="113px">Designation</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="<td  align="left" valign="top" style="width: 188px">";
                objMailMessage.Body +="<asp:Label ID="txtdesignation" CssClass="lblBoldBlue"  runat="server">";
                objMailMessage.Body +="</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";
                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr>";
                objMailMessage.Body +="<td align="right" style="width: 491px">";
                objMailMessage.Body +="<asp:Label ID="lbldepartment" CssClass="lbl" runat="server"  Width="113px">Department</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="<td  align="left" valign="top" style="width: 188px">";
                objMailMessage.Body +="<asp:Label ID="txtdepartment" CssClass="lblBoldBlue"  runat="server">";
                objMailMessage.Body +="</asp:Label>";
                objMailMessage.Body +="</td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";
                objMailMessage.Body +="<table>";
                objMailMessage.Body +="<tr>";
                objMailMessage.Body +="<td align="left"  valign="top">";
                objMailMessage.Body +="<asp:Label ID="lblNotifiedDate" CssClass="lbl" runat="server" >Date</asp:Label></td>";
                objMailMessage.Body +="<td valign="top" align="left">";
                objMailMessage.Body +="<asp:TextBox ID="txtNotifiedDate" ReadOnly="true" CssClass="lbl"  runat="server" Width="103px"></asp:TextBox></td>";
                objMailMessage.Body +="</tr>";
                objMailMessage.Body +="</table>";



                objMailMessage.IsBodyHtml = true;
                string sSmtpIp = lib.getSmtpIp(company);
                string[] sSmtpIpArr = sSmtpIp.Split(',');
                string sIp = "";
                int iPort = 0;
                if (sSmtpIpArr.Length == 2)
                {
                    sIp = Convert.ToString(sSmtpIpArr[0]);
                    iPort = Convert.ToInt32(sSmtpIpArr[1]);
                }

                SmtpClient objSmtp = new SmtpClient(sIp, iPort);
                objSmtp.Send(objMailMessage);
                sEmailSend = 1;
            }
            catch (Exception ex)
            {
                sEmailSend = 0;
            }
            return sEmailSend;
        }


Edit TR: What's your question?
Posted
Updated 30-Apr-10 0:57am
v2

1 solution

You use " inside your strings:

Example:
C#
objMailMessage.Body +="<asp:Label ID="lblname" CssClass="lbl" runat="server" Width="113px">name:</asp:Label>";



This is simply not possible, just replace them with '

like this:

C#
objMailMessage.Body +="<asp:Label ID='lblname' CssClass='lbl' Width='113px'>name:</asp:Label>


I'm also not too sure if an e-mail will support ASP code -_-
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900