मुझे ईमेल में एक प्रश्न के परिणाम भेजने की आवश्यकता है।ईमेल में एक तालिका भेजें
GetDataTable():: मैं दो तरीकों का उपयोग कर रहा क्वेरी निष्पादित और datatable प्राप्त करने के लिए (जो ईमेल में भेजे जाने की आवश्यकता)
SendAutomatedEmail(): स्वचालित ईमेल भेजने के लिए।
समस्या: मुझे ईमेल में डेटा तालिका या HTML तालिका भेजने की आवश्यकता है, नीचे दिए गए कोड की तरह कुछ। इस DataTable
public static void Main(string[] args)
{
DataTable datatable = GetDataTable();
SendAutomatedEmail(datatable);
}
public static DataTable GetDataTable(string CommandText)
{
string cnString = ConfigurationManager.ConnectionStrings["Connection2"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(cnString);
string CommandText = "select * from dbo.fs010100 (nolock)";
SqlCommand sqlCommand = new SqlCommand(CommandText, sqlConnection);
SqlDataAdapter sqlDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
sqlDataAdapter.SelectCommand = sqlCommand;
DataTable dataTable = new DataTable();
dataTable.Locale = System.Globalization.CultureInfo.InvariantCulture;
// Adds or refreshes rows in the DataSet to match those in the data source
try
{
sqlDataAdapter.Fill(dataTable);
sqlConnection.Close(dataTable);
}
catch (Exception _Exception)
{
sqlConnection.Close();
//Console.WriteLine(_Exception.Message);
return null;
}
return dataTable;
}
public static void SendAutomatedEmail(DataTable dt, string recipient = "[email protected]")
{
try
{
string mailServer = "server.com";
MailMessage message = new MailMessage(
"[email protected]",
recipient,
"Test Email",
dt.ToString()
);
SmtpClient client = new SmtpClient(mailServer);
var AuthenticationDetails = new NetworkCredential("[email protected]", "password");
client.Credentials = AuthenticationDetails;
client.Send(message);
}
catch (Exception e)
{
}
}
तालिका ईमेल के मुख्य भाग में होना जरूरी है? – AllenG
हाँ, ईमेल की सामग्री तालिका – 14578446
तुम सिर्फ एक मेज के निर्माण के लिए कच्चे एचटीएमएल बाहर लिख सकते हैं, और ईमेल के शरीर में डाल दिया, उदा .: