Function to send mail from sql server

Q & AFunction to send mail from sql server
Admin Staff asked 4 years ago

Function to send mail from sql server

1 Answers
Admin Staff answered 4 years ago

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER FUNCTION getmail
(
  @from varchar(50),
  @to varchar(500),
  @subject varchar(100),
  @BCC varchar(500),
  @FROM_NAME varchar(50),
  @MailBody varchar(8000)
)
RETURNS int
AS
BEGIN
  declare @rc as int
  exec @rc = master.dbo.xp_smtp_sendmail
  @FROM= @from,
  @FROM_NAME= @FROM_NAME,
  @TO= @to,
  @BCC= @BCC,
  @subject= @Subject,
  @message= @MailBody,
  @type= N’text/html’,
  @server= mailserverip
  return @rc
END