I have set up database mail in SQL 2005 and it works fine when I am sending mail from within Agent Jobs. Also works fine when I send a test email by right clicking database mail and using Send Test Email....
However, when I try and send an email using the following, I get an error:
EXEC msdb.dbo.sp_send_dbmail
@recipients='my email address',
@subject = 'Test Email',
@body = 'I am Testing Email for SQL',
@body_format = 'HTML'
Below is the message from the mail log
Message
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2013-09-23T12:22:27). Exception Message: Cannot send mails to mail server. (The SMTP server requires a secure connection or the client was not authenticated.
The server response was: 5.5.1 Authentication Required. Learn more at).
)
What am I doing wrong?