I need to send mail through sqlserver 2005!
thanks in advance
regards,
gowtham,
eternalsoftwares,
chennai.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jun 5, 2011, 9:34 PM EDT
The following script will send an e-mail with an attached file named FileAttachment.txt, which is located on my C: drive. You will need to make sure that this file exists so that the procedure does not error.
EXEC msdb.dbo.sp_send_dbmail @recipients=N'[email protected]', @body='Message Body', @subject ='Message Subject', @profile_name ='Database-mailProfile', @file_attachments ='C:\FileAttachment.txt';Gowtham manju157 reputationPosted Jun 5, 2011, 9:57 PM EDT
i too tried the same code but got error such as
Cannot add rows to sysdepends for the current stored procedure because it depends on the missing object 'master.dbo.sp_sendmail'. The stored procedure will still be created.
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jun 5, 2011, 10:35 PM EDT
Create Stored procedure and use that code in that SP....
Gowtham manju157 reputationPosted Jun 5, 2011, 10:38 PM EDT
the coding which i created was
use master
go
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE sendemail1 @subjectText varchar(5000), @bodytext varchar(5000), @to varchar(150)
AS
BEGIN exec master.dbo.sp_sendmail
@recipients='[email protected]',
@copy_recipients='[email protected]',
@subject ='hi',
@body = 'sample',
@body_format = 'HTML' ;
END
GO
but i am getting those errors
can u guide me
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jun 5, 2011, 10:42 PM EDT
write a sendmail method in code-behind...There use these values...
Refer Create SP's and how to send mail articles
Gowtham manju157 reputationPosted Jun 5, 2011, 10:47 PM EDT
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jun 5, 2011, 11:00 PM EDT
refer
http://msdn.microsoft.com/en-us/library/ms378108%28v=sql.90%29.aspx
http://vstoolsforum.com/blogs/sqlserver/archive/2007/04/20/creating-a-stored-procedure-with-output-parameters.aspx
Gowtham manju157 reputationPosted Jun 5, 2011, 11:05 PM EDT
i do not get the proper idea to follow do not mistaken me
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jun 5, 2011, 11:15 PM EDT
Write all this under Submit button click event
write a select query and get the required values like this
string selectquery = "";
selectquery = "select RID, UserName, Email_Id, CONVERT(varchar, DOB, 103) AS DOB, CONVERT(varchar, DOJ, 103) AS DOJ, State, Pin_Code FROM Registration where RID=" + hdnvalue;
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["SqlServer"]);
SqlCommand sqlcomm = new SqlCommand();
sqlcomm = sqlcon.CreateCommand();
sqlcomm.CommandType = CommandType.Text;
sqlcomm.CommandText = selectquery;
sqlcon.Open();
SqlDataReader sqlred = null;
sqlred = sqlcomm.ExecuteReader();
if (sqlred.Read())
{
if (sqlred["UserName"] != null)
{
String strFrom = sqlred["UserName"].ToString();
}
if (sqlred["Email_Id"] != null)
{
string strTo= sqlred["Email_Id"].ToString();
}
if (sqlred["DOJ"] != null)
{
string strSubject= sqlred["DOJ"].ToString();
}
if (sqlred["Pin_Code"] != null)
{
string strbodytext= sqlred["Pin_Code"].ToString();
}
}
sqlcomm.Dispose();
sqlcon.Close();
SmtpMail.Send(strFrom, strTo, strSubject, strbodytext);
Response.Write("Message was sent to" + strTo);
Modify this to your requirement..............
Suthish NairRank #92 · 22.8K reputationPosted Jun 6, 2011, 3:03 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Jun 6, 2011, 3:05 AM EDT