Comments (76)

  1. Balmukund says:

    Suhas,

    Thanks for detailed steps.

    It is certainly going to help for those who want to use SMTP of Live or Gmail to configure Database Mail.

    Great work!

    Thanks

    Balmukund

  2. Aric says:

    when i am trying to setup account with gmail at that time i am receiving following error

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 11 (2009-09-16T15:42:39). 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.7.0 Must issue a STARTTLS command first. 2sm877726qwi.32

    Please let me know how to solve this error.

    Thanks

  3. Suhas De says:

    Hi Aric,

    This issue has nothing to do with SQL Server Database Mail system. This mostly looks like an issue with the configuration.

    Make sure you have specified the SMTP server name and the port number properly. If your SMTP server requires SSL, make sure Basic Authentication is used and the user name and password is entered properly.

    Most of the issues we see on this error points us to an invalid SMTP Server Name or an invalid port. For example, many websites suggest using port 465 for sending emails through gmail; however, we have seen that port 465 does not work. Port 587 just works fine.

    Please let me know if this is useful.

    Thanks,

    Suhas

  4. mohammad says:

    hi there

    thank you for this article

    it was useful

    by the way i agree with Suhas in which Google defined 2 ports (465 and 587) but only 587 works.

    it took 2 hour to get it !

  5. Les says:

    Fine – but if the only mailserver is Exchange how do I go about configering my Exchange to accept SMTP or how do I build a SMTP server

  6. Suhas De says:

    Hi Les,

    For configuring Exchange to accept SMTP or to build a SMTP server, please get in touch with your Exchange Administrator. I will not be able to help you here as I do not have knowledge on Exchange.

    Thanks,

    Suhas

  7. Ashish Gupta says:

    Thanks Suhas , its been a great help ,Mail setup was successful .

    thanks

    Regards

    Ashish Gupta

  8. manjunadh says:

    Hai Friend,here am new to the SQL Server 2005 …plz help me …when i right click on the Database mail,it showing only refresh option i din’t get any other options like..configure Database Mail….so plzz help me what i have to do now…

    1. Sanjay B says:

      Hi Manjunath,
      Execute this command- Sp_configure ‘Database Mail XPs’, 1
      Reconfigure
      And then try configuring DB mail.

  9. Suhas De says:

    I don’t think I remember seeing anything like this. Can you execute "select @@version" and paste in the output? May be we can find some clues from this.

    Suhas

  10. Atif says:

    Hi,

    I do the same thing as you mention in snaps for gmail account port is 587 and every thing is exactly same

    But i got this error

    Message

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 8 (2009-12-22T16:47:11). Exception Message: Cannot send mails to mail server. (The operation has timed out.).

    )

    Can any body give me solution

  11. londhe.kunal says:

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2010-01-19T13:54:43). 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                              ). )

  12. Suhas De says:

    Hi Atif and Kunal,

    Are you inside a corpnet? Are you accessing the internet through a Proxy?

    If you are, then neither will work. You have to be on the Live Internet for this to work.

    Suhas

  13. Devesh says:

    Hi, Is there any option such as My smtp requires authentication as in Outlook because I get an error:

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2010-02-11T18:10:33). Exception Message: Cannot send mails to mail server. (Mailbox unavailable. The server response was: must be authenticated).

  14. Chitra says:

    Hi Suhas,

    I have configured the Database Mail, and the test email is successful. I have to also use this database Mail profile and build the SQL Server Agent job called Automated Email. When the job run, I want the email to be sent to the administrators that backup job was successsful and it should include all the files created in the backup process. So in the job command the code is as the following: The job runs successfully but when I add the following parameter but this parameter is not working @file_attachment = ‘C:Program FilesMicrosoft SQL Server…..error the Access denied.

    What is the right way to work on that, how do I cross this hurdle. I am using sqlserver 2005.

    Use msdb

    GO

    EXEC sp_send_dbmail  @profile_name =’DB Mail Profile’,

    @recipients =’csaha@imsa.edu’,

    @copy_recipients =’csaha@imsa.edu’,

    @blind_copy_recipients=’csaha@imsa.edu’,

    @body =’This is a test message’,

    @subject=’Database Backup’,

    @body_format=’TEXT’,

    @importance=’Normal’,

    @sensitivity=’Normal’

    Chitra

  15. Srinvias says:

    Chitra,

    If you are using SQL server to send email attachment files in systems other than SQL Server will not be accepted. Use Windows account and provide access to the directory .

    Is C: you are referring to is on database server or on some other system ?

    Thanks

    Srinvas

  16. Chitra says:

    Hi Srinivas,

    I am using SQL Server to send email. C drive is

    in sqlserver 2005. All I need to do is after the backup job is successful it will be reading the all backup file

    names. Some else also suggested me to use Windows account and provide access to the directory, but I do not know how that is possible. Any advice in that respect will be of great help.

    Thanks

    Chitra

  17. Suhas De says:

    Hi Chitra,

    Here’s some information from the Books Online:

    "Database Mail uses the Microsoft Windows security context of the current user to control access to files. Therefore, users who are authenticated with SQL Server Authentication cannot attach files using @file_attachments. Windows does not allow SQL Server to provide credentials from a remote computer to another remote computer. Therefore, Database Mail may not be able to attach files from a network share in cases where the command is run from a computer other than the computer that SQL Server runs on."

    So, 2 things that you might want to check:

    1. Are you logged on to SQL Server using Windows Authentication?

    2. Does this Windows Account have permission to the file you are trying to attach?

    If your answer is "NO" for any of these, you cannot send a file as an attachment.

  18. Suhas De says:

    Chitra, please connect with me offline (using the EMAIL link on the top), if you need any further assistance. It seems that you have a unique requirement and to provide a solution, we need to understand your requirement better.

  19. Chitra says:

    Hi Suhas,

    The answer to the above two questions are no, I am using a sql authentication account. However for the job to be successful I can use a windows account.

  20. Suhas De says:

    Hi Chitra,

    You have to use a Windows Account. I am not sure if the account needs SysAdmin privileges in SQL Server. I am sure you will be able to figure that out yourself.

    Make sure that the Windows Account you use has READ permission on the folder containing your backup set.

    Suhas

  21. sivakumar says:

    I want to store email content to database. Is it possible.

    mail me at

    nsivaa at gmail dot com

  22. Nainesh says:

    Hi masters i want to send mail using my exchange server

    when my job is complete so how to do it guide me.

  23. Suhas De says:

    Hi Siva,

    Database Mail is for sending email, not receiving or reading email. Your objective can be fulfilled only by a custom application that reads email and enters that into SQL Server.

    Hi Nainesh,

    You need to get the exchange server details from your exchange admin. Use these details to configure DBMail, and you should be able to send email.

    Suhas

  24. Ramat says:

    Hi all,

    I have followed the steps above in configuring database mial but I keep getting errors when i send the test emails.

    Using live mail, I get the following

    "The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 9 (2010-03-07T16:44:27). Exception Message: Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 65.55.172.254:25)".

    Using gmail, I get the following

    "The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2010-03-07T17:04:26). 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."

    I used the correct port numbers.

    Please help!!!!!!!

  25. Suhas De says:

    Hi Ramat,

    Are you behind a proxy or a firewall? Unless you are connected to the Live Internet, sending email using your Live Account or Gmail account will not be possible.

    Thanks,

    Suhas

  26. Carlo says:

    Thanks! Had some problems with GMAIL. I was using port 465 and nothing worked then I read your comments and realized I should be using 587. Everything works now!!!

  27. karthik says:

    how to troubleshoot slow running queries through profiler

  28. Suhas De says:

    Hi Karthik

    Use SQLNexus (http://sqlnexus.codeplex.com/).

    Load the Profiler traces into a SQL Server Database using SQLNexus and then look at the top duration batches, the statements within and their plans.

    Suhas

  29. Kamlesh says:

    Hi Suhas,

    I have followed the instruction which you mentioned above but when I send a mail while some difficult problem occurred. Few mails got delivered and few mails not, whatever mails are not delivered that gives error

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 23 (2010-10-15T16:19:21). 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                              ). )

  30. Suhas De says:

    Kamlesh, the error message says that the issue is due to a Mail Server Failure. DBMail tried sending the email, but the client could not be authenticated. This failure is outside the SQL Server, i.e., at the mail server. Please contact your email administrator for a resolution.

    Alos, if you are trying to use DBMail with Live Mail or GMail, you will need a paid membership if you want to send emails in bulk. For free accounts, they will not allow you to spam the SMTP Server.

  31. Kamlesh says:

    Hi Suhas,

    I can send mail from sql server 2008 but the problem is that I could not send mail in HTML format. It shows text format.

    Is there any way send it in HTML format…….

  32. Kamlesh says:

    Hi Suhas,

    Thank you so much for solving my problem…….

    But Suhas, I have found the way the to send mail in html format that is "@body_format='HTML'". In this way we can send it.

    I hope you know this…

    then also i want to confirm that        Is that right format??????

  33. Suhas De says:

    Sorry Kamlesh, I overlooked that. Yes, you can use @body_format = 'HTML' to send emails in HTML format.

    [ @body_format = ] 'body_format'

    Is the format of the message body. The parameter is of type varchar(20), with a default of NULL. When specified, the headers of the outgoing message are set to indicate that the message body has the specified format. The parameter may contain one of the following values:

    TEXT

    HTML

    Defaults to TEXT.

  34. Kamlesh says:

    Hi Suhas,

    Thank you so much…………

  35. Kamlesh says:

    Hi Suhas,

    i am declaring local variable in MSSQL with type varchar with the size of MAX but it takes only 8001 character only.

    I couldn't able to set more characters in local variable….

    please advice on this issue.

  36. Kamlesh says:

    HI Suhas,

    Can we run the Store Procedure without calling it from the front end. The store procedure should run every 1hour.

    Is it possible?

  37. balaji says:

    I have configured mail using port 587 . but this error is coming again "The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2011-02-05T23:04:48). Exception Message: Could not connect to mail server. (No connection could be made because the target machine actively refused it 74.125.155.109:587). )" . I have turned the firewall off . I am using SQL Server 2008 . Please help me .

  38. Gloria Del Villar says:

    Hola, ya realice la configuracion, solo que tengo la situacion que en ocaciones no manda los correos y no se porque razon.

    me podrian ayudar ¡¡¡¡

  39. Brian Mullins says:

    Ok i have tried many times and still no luck.. smtp and port is set. What do you exactly mean by live internet… i use 192.16.0.1 as a proxy for me to be able to use the internet is that a problem? not really understanding why a proxy is blocking it

  40. Efi says:

    Hi,

    i want  to configure the db mail and i get the error The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 14 (2011-09-14T13:35:07). Exception Message: Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time<c/> or established connection failed because connected host has failed to respond).

    )

    i am behind a proxy and i try to user gmail smtp. what do i need to do in this case? how can i configure it?

    thanks!

    Efi

  41. Suhas De says:

    Hi Brian / Efi, To be able to send email, the SQL Server must be able to talk directly with the SMTP Server. Most proxies work as HTTP proxies; that is, your HTTP request (from your web browser) goes to the Proxy Server, and the Proxy Server connects to the Internet to get that data for you. Later, that data is sent back by the Proxy Server to your browser (after optionally caching the page on the proxy server). These proxies cannot interprete or forward SMTP requests. Hence, if your SQL Server is not connected to the Internet (using an Internet IP Address), DBMail does not work.

    If you want to remain behind a proxy and still want to be able to send emails using GMail or Live Mail, you will need to have, what is called an SMTP Proxy. Bing search can pull up list of SMTP Proxy (Microsoft has no product on these lines), but you will need to evaluate (and buy) the best ones.

    Hope this helps.

    Thanks, Suhas

  42. Rene Villeda says:

    @Gloria Del Villar

    Quizá bastante tarde, pero ¿podrías poner el error que genera SQL Server?

    Yo tengo un problema similar a este:

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 4 (2011-11-04T11:02:24). Exception Message: Cannot send mails to mail server. (Client does not have permission to submit mail to this server. The server response was: 5.7.3 Client was not authenticated.).

    )

    Pero estoy en platicas con el administrador de correo (exchange) para ver si es por puertos o alguna configuración

    Saludos

  43. Mark Leja says:

    From the list of question this process does not sound like it is worth attempting. I cannot even find my gmail setting. I finally found gmail help but cannot see the sort of information you are requesting.

  44. Peter Lee says:

    I got the following error when I try my Gmail account: The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2012-02-28T18:11:26). Exception Message: Could not connect to mail server. (The requested name is valid, but no data of the requested type was found). )

  45. JFang says:

    It worked, thanks a lot.

    I think I was having problem with my mail server, bc it worked with my live account.

  46. Diana says:

    Hi all,

    I follow all the steps you provide. And I get this error when I use Gmail as my SMTP Server :

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2012-04-09T20:28:01). 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). )

    really need your help !thanks

  47. Ganpat Sharma says:

    Hi everyone.

    i am sending email from sql server 2008 r2.

    database mail configuration details set as :

    ————————————————————–

    Server Name : smtp.gmail.com

    Port No : 587

    Set Basic Authentication : User Name, Password

    i tried more but email sending is failed and error occur is-:

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2012-05-03T15:46:30). Exception Message: Could not connect to mail server. (An attempt was made to access a socket in a way forbidden by its access permissions 173.194.79.108:587). )

    Please i need your help i can solve this problem . please give suggetion.

    Thanks and Regards:

    Ganpat Sharma

  48. Rahul says:

    Use msdb

    GO

    EXEC sp_send_dbmail  @profile_name ='DB Mail Profile',

    @recipients ='csaha@imsa.edu',

    @copy_recipients ='csaha@imsa.edu',

    @blind_copy_recipients='csaha@imsa.edu',

    @body ='This is a test message',

    @subject='Database Backup',

    @body_format='TEXT',

    @importance='Normal',

    @sensitivity='Normal'

    ———–

    Result —- Mail Queued

  49. kiran says:

    After configuring while trying to send test mail,

    in log it is showing error message like—"The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2012-06-12T12:28:45). Exception Message: Could not connect to mail server. (No connection could be made because the target machine actively refused it 173.194.79.109:587)."

    Can u pls help me out

  50. Arjun says:

    Dear But i am not able to find the database mail option so what should i do for it?

  51. Apexa says:

    When I try to send test mail it gives me error like this . "The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2013-09-11T17:50:46). 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.7.0 Must issue a STARTTLS command first. f2sm28525069pbg.44 – gsmtp).

    )"

  52. TP says:

    I am getting the similar error.  Any clue?

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2013-10-09T11:47:49). Exception Message: Could not connect to mail server. (An attempt was made to access a socket in a way forbidden by its access permissions 172.29.4.29:25). )

  53. Ganesh says:

    Hi

    i have all the steps after configuring  mail i am trying to send test mail while sending test main

    i got below given error plz help me

    Message

    1) Exception Information

    ===================

    Exception Type: System.NullReferenceException

    Message: Object reference not set to an instance of an object.

    Data: System.Collections.ListDictionaryInternal

    TargetSite: Microsoft.SqlServer.Management.SqlIMail.Server.Objects.Account GetAccount(Int32)

    HelpLink: NULL

    Source: DatabaseMailEngine

    if possible send me the solution to my mail id

    ganesh.vidiyala@gmail.com

  54. shiv says:

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2013-11-05T12:59:17). Exception Message: Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time, or

    established connection failed because connected host has failed to respond 67.215.65.131:587). )

  55. Moein Mohebbi says:

    When I try to send test mail it gives me error like this,:

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2013-12-19T12:05:38). 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.7.0 Must issue a STARTTLS command first. tn8sm2728017bkb.16 – gsmtp).

    )

    could you please help me,

    this is my Email : mohebi@ideaco .ir

    many thanks

  56. Moein Mohebbi says:

    When I try to send test mail it gives me error like this,:

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2013-12-19T12:05:38). 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.7.0 Must issue a STARTTLS command first. tn8sm2728017bkb.16 – gsmtp).

    )

    could you please help me,

    this is my Email : mohebi@ideaco .ir

    many thanks

  57. Jerry says:

    Ha! I just figure out my SMTP 587 port(465 not work), after 2 hours googling and trying…..

  58. Niranjan Poddar says:

    Thanks sir,,,,,,,,,,,,this post is helpful for me……..

  59. rahan says:

    my sql server 2008

    no dabasemail under management

    why?

    what will do?

  60. Sunil says:

    HI All,

    I am getting below error when i try to send a test mail. Can any one help here.

    "The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2014-08-12T02:08:00). Exception Message: Could not connect to mail server. (An attempt was made to access a socket in a way forbidden by its access permissions 10.161.196.45:25).

    )"

    Thanks in advance

  61. Leena Jyotishi says:

    In Profile i have used two account. I have faced issues that mail send twice some times.

    Can you help me for this ?

  62. Bijo says:

    Good!!!Thanks a lot. Its really works!!

  63. Anh Hoang says:

    For someone get the error:

    "The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2010-02-11T18:10:33). Exception Message: Cannot send mails to mail server. (Mailbox unavailable. The server response was: must be authenticated)."

    Please try to change the Server Name to: smtp.googlemail.com

  64. Julak Doom says:

    For GMail SMTP access to work, you must enable so called "Less Secure Apps" feature at http://www.google.com/…/lesssecureapps

    If you dont do this, authentication attempt will be blocked by GMail.

  65. luke says:

    Wtf all those blogs were useless i didn't understand any of them surely there is a much simpler way to tell me how to fix the problem now i really don't know what to do thanx for that waste of time

  66. Satrugna says:

    Hi,

    I am getting below error while sending test mail.What is the issue?

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2015-05-17T22:02:51). Exception Message: Could not connect to mail server. (An attempt was made to access a socket in a way forbidden by its access permissions 74.125.130.109:587). )

  67. Kiran Kumar says:

    getting this kind of error while trying to send test email

    "The SMTP server requires a secure connection or the client was not authenticated"

    can any one help me out please

  68. Kalyan says:

    Hi All,

    Even after you give, all the apt details your test mails will not be delivered because they will be blocked by google account policies or Internet Explorer Enhanced Security Configuration 'IE ESC'

    1: Disable 'IE ESC' (Start>Administrative Tools> Server Manager>Configure IE ESC (Right Hand Side, middle of the page, last row)>Left Click> Off for Administrators & Users)

    2. Verify you gmail inbox for any blocked alerts from google.

    If you open you see something like 'if this was you' select the given url, now you will be directed to a page something like 'Less Secure apps' click on 'Turn On'

    Now try to send a test mail again and check your inbox, you'll get it!!!!!!!

    Least bothered about time……

    Regards,

    Kalyan

  69. Phani says:

    Excellent Post, thank you very much

  70. Bhuvneshwar says:

    Hi All,

    i have configured yahoo mail id successfull but i sent a test mail. but mail is not going.

    Please help me in this issue asap.

  71. Bipin Singh says:

    Very nice article and very descriptive language. Everything worked in one attempt

  72. Shailendra says:

    Can we use gmail account with two step verification turned on?

  73. jitendra says:

    I have configure the setting but unable to send mail below error is coming:-

    The mail could not be sent to the recipients because of the mail server failure.

    (Sending Mail using Account 4 (2016-01-12T20:18:01). 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).  )

    Please help

  74. Venkatesh says:

    Hi,

     I have configured database mail behind firewall ON. I am getting below Error

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2016-02-26T16:16:03). Exception Message: Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

    Please Help me.

  75. Sanjeev Sharma says:

    I am facing a problem.
    “The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2016-06-07T10:47:44). Exception Message: Cannot send mails to mail server. (The remote certificate is invalid according to the validation procedure.).”

    Please help?