如何使用大量文本数据从.NET应用程序向Outlook发送电子邮件/ [英] How to send email from .NET application to outlook with large amount of text data /

查看:81
本文介绍了如何使用大量文本数据从.NET应用程序向Outlook发送电子邮件/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

电子邮件是包含5到6页的大量数据,包含项目符号,标题和表格。除标题外,数据是从.NEt应用程序中随机生成的。有人可以建议哪个.NEt类支持接受大数据作为主体参数。



我尝试过:



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.

推荐答案

通过C#发送电子邮件非常简单。请参阅此链接以获取示例:如何从C#发送电子邮件 [ ^ ]



System.Net命名空间是你需要的。
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.


System.Net.Mail是发送电子邮件的命名空间。



电子邮件本身包含在MailMessage类中。

电子邮件的正文是字符串类型。

字符串的长度是 int 的类型,其中最大值为2,147,483,647

含糊不清的术语页面相当于大约500个单词或3000个字符。

相当于约715,000页。
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.


我在我的解决方案之下,

我的公司防火墙限制从.NEt应用程序发送电子邮件,所有SMTP服务器设置都已在SQL Server中配置。所以我正在使用 msdb.Sp_dbmail

我正在发送HTML格式的邮件正文。

下面的代码很好用。



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.

<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());
     }




<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");
        }







<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


这篇关于如何使用大量文本数据从.NET应用程序向Outlook发送电子邮件/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆