Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The email is large amount of data with 5 to 6 pages , with bullets and headings and tables. Except headings , data is randomly generating from .NEt application . Could someone suggest which .NEt class supports accepting large data as body parameter.

What I have tried:

I have tried with  sp_send_dbmail , but  seems it accept html format input as a body from .NEt application. As per the requirement, the body is not static to send as a big string.
Posted
Updated 26-Sep-18 4:58am

Sending emails via C# is very simple. See this link for an example: How to send email from C#[^]

The System.Net namespace is what you need.
 
Share this answer
 
System.Net.Mail is the namespace for sending email.

The email itself is contained within the MailMessage class.
The body of an email is of type string.
The length of a string is of type int, of which the max value of 2,147,483,647
The ambiguous term "page" equates to approximately 500 words or 3000 characters.
That equates to about 715 thousand pages.
 
Share this answer
 
I am following below my solution,
My company firewall is restricting sending emails from .NEt application, all SMTP server settings have been configured in SQL server. So i am using msdb.Sp_dbmail.
And i am sending mail body in HTML format.
Below code works good.

C#
<pre>  SqlConnection connLMSSQL01 = new SqlConnection("Data Source=AAA;Initial Catalog=BBB;Persist Security Info=True;User ID=CCC;Password=***");
        SqlCommand cmdValidateUser;


<pre lang="c#">
private void button2_Click(object sender, EventArgs e)
     {
         StringBuilder HtmlMessageBody = new StringBuilder();
         HtmlMessageBody.Append("<html><body> ");
         HtmlMessageBody.Append("<p> <h1>Welcome ! </h1> <br> <br> </p> ");

         HtmlMessageBody.Append("</body></html>");
         SendEmail(HtmlMessageBody.ToString());
     }

C#
<pre> public void SendEmail(string HtmlMessageBody)
        {
            cmdValidateUser = new SqlCommand();
            cmdValidateUser.CommandText = "SendEmail";
            cmdValidateUser.CommandType = CommandType.StoredProcedure;
            cmdValidateUser.Connection = connLMSSQL01;
            connLMSSQL01.Open();
            cmdValidateUser.Parameters.Add("@HtmlMessageBody", SqlDbType.VarChar, 800000);
            cmdValidateUser.Parameters["@HtmlMessageBody"].Value = HtmlMessageBody;
            cmdValidateUser.ExecuteNonQuery();
            cmdValidateUser.Dispose();
            connLMSSQL01.Close();

            MessageBox.Show("Mail Sent");
        }


SQL
<pre>CREATE PROCEDURE [dbo].[SendEmail](@HtmlMessageBody   varchar (MAX) )

  AS
  BEGIN

EXEC msdb.dbo.sp_send_dbmail 
@recipients='XXX@gmail.com',
@subject = 'Send Email- HTML Body',
@body = @HtmlMessageBody,
@body_format = 'HTML' 

END
 
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