<appSettings>
<add key= "Mailprofile" value= "AAA"/> </appSettings>
private void Btnsendmail ()
{
Try
{
String mailprofile = configurationmanager.appsettings["Mailprofile"];
string receivers = "[email protected]";
String cc = "";
string connectionString = configurationmanager.connectionstrings["BB"]. ConnectionString;
String subject = "Subject";
string fileattachments = string. Empty;
string BODY = string. Empty;
\ r indicates carriage return, \ n the line is generally \ r \ n
BODY = "Hi gugs:\r\n\r\n";
BODY = body + "\r\n\r\n Source:" + comsource.text;
BODY = body + "\r\n\r\n Thanks";
Initialize the parameters of the stored procedure
var parammailprofile = new SqlParameter ("@profile_name", SqlDbType.NVarChar, +) {Value = Mailprofil e};
var paramreceivers = new SqlParameter ("@recipients", SqlDbType.NVarChar,-1) {Value = receivers};
var paramcc = new SqlParameter ("@copy_recipients", SqlDbType.NVarChar, 255) {Value = cc};
var parambody = new SqlParameter ("@body", SqlDbType.NVarChar,-1) {Value = body};
var paramsubject = new SqlParameter ("@subject", SqlDbType.NVarChar, 255) {Value = subject};
var paramfileattachments = new SqlParameter ("@file_attachments", SqlDbType.NVarChar,-1) {Value = fil Eattachments};
using (var conn = new SqlConnection (connectionString))
using (var cmd = new SqlCommand ("Msdb.dbo.sp_send_dbmail", conn)
{
CommandType = CommandType.StoredProcedure,
CommandTimeout =.
})
{
cmd. Parameters.addrange (new[] {parammailprofile, paramreceivers, PARAMCC, Parambody, Paramsubject, paramFileAttachments} );
Conn. Open ();
cmd. ExecuteNonQuery ();
}
}
catch (Exception ex)
{
return;
}
}
C # calls SQL Server sp_send_dbmail stored procedure to send mail