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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Jun 6, 2011, 7:05 AM
Suthish NairPosted Jun 6, 2011, 7:03 AM
Jiteendra SampathiraoPosted Jun 6, 2011, 3:15 AM
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..............
Gowtham manjuPosted Jun 6, 2011, 3:05 AM
i do not get the proper idea to follow do not mistaken me
Jiteendra SampathiraoPosted Jun 6, 2011, 3:00 AM
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 manjuPosted Jun 6, 2011, 2:47 AM
Jiteendra SampathiraoPosted Jun 6, 2011, 2:42 AM
write a sendmail method in code-behind...There use these values...
Refer Create SP's and how to send mail articles
Gowtham manjuPosted Jun 6, 2011, 2:38 AM
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 SampathiraoPosted Jun 6, 2011, 2:35 AM
Create Stored procedure and use that code in that SP....
Gowtham manjuPosted Jun 6, 2011, 1:57 AM
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.
Jaganathan BantheswaranPosted Jun 6, 2011, 1:34 AM
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.