How to configure SQL Server Database Mail to send email using your Windows Live Mail Account or your GMail Account
Hi Friends,
This post comes as a response to requests from many of our customers, who want to know the step by step process on how to configure SQL Server Database Mail to send emails using their Windows Live Mail Account or their Gmail Account.
If you are using SQL Server 2005 or higher, you might have noticed that there is now a “Database Mail” (DB Mail) option under “Management” . This is very different from the “SQL Mail” that we had on previous versions (it still exists under Management\Legacy). Using DB Mail, you no longer have to configure a mailbox on your machine, and you certainly do not need to run the SQL Server or the SQL Server Agent under the account you want to send emails from. Moreover, you can have multiple mail profiles and you can decide which account to use under various conditions.
So, here we go on the steps to configure DB Mail:
Right-Click on Database Mail and choose Configure Database Mail.
This starts the Database Mail Configuration Wizard. Click Next.
In the Select Configuration Task screen, choose “Set up Database Mail by performing the following tasks:” and click “Next” .
Now, you will be required to enter a Profile Name. This can be any Arbitrary Name that will help you identify the Profile. You might also want to add a Description. Now, click on Add.
Now, you are prompted to create a New Database Mail Account. Enter any Account Name and Description. The other parameters are as follows:
For configuring Windows Live Mail:
Email address: Your Live e-mail ID
Display name: Your name
Reply e-mail: Any reply-to email account
Server name: smtp.live.com
Port number: 25
This server requires a secure connection (SSL): Checked ONIn the next section, choose Basic Authentication and enter the following information:
User name: Your Live e-mail ID
Password: Password for your Live e-mail ID
Confirm password: Password for your Live e-mail IDThe configuration should look like the screenshot below. Now, click OK.
For configuring Google Mail (Gmail):
Email address: Your Gmail ID
Display name: Your name
Reply e-mail: Any reply-to email account
Server name: smtp.gmail.com
Port number: 587
This server requires a secure connection (SSL): Checked ON
(Settings looked up from Gmail Help)In the next section, choose Basic Authentication and enter the following information:
User name: Your gmail ID
Password: Password for your gmail ID
Confirm password: Password for your gmail IDThe configuration should look like the screenshot below. Now, click OK.
Back on the New Profile screen, click Next. The next Manage Profile Security screen allows you to set the Public Profiles, the Private Profiles and the Default Profiles for each of the Public and Private Profiles.
Click Next. This will move us to the Configure System Parameters screen. You may want to tweak the parameters; however, for demonstration purposes, we will keep these as default. Now, click Next.
In the Complete the Wizard screen, review the parameters and click Finish. Ensure that all the 5 Actions succeed and then click Close.
Your DB Mail should now be configured successfully and you should be all setup to send emails using DB Mail. But before we confirm success, we will like to send a test email and confirm receipt. To do that, right-click on Database Mail and choose Send Test E-Mail…
Enter a To: email id and click Send Test E-Mail.
You should receive the email in a few seconds. If you have received the email, you have been able to configure DB Mail successfully, and you can now start using DB Mail.
Hope this post will be helpful.
Disclaimer:
None of the email addresses used in this post belong to me. Please do not try to contact me in any of these email addresses, as your emails will never reach me. All information provided here is my personal opinion and is neither verified nor approved by Microsoft before it is published. All information, and code samples, if any, is provided "AS IS" with no warranties and confers no rights.
Request to my readers: Please let me know on what topics you would like me write on. I would be happy to be of any help to my readers.
Comments
Anonymous
July 12, 2009
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 BalmukundAnonymous
September 16, 2009
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. ThanksAnonymous
September 22, 2009
The comment has been removedAnonymous
October 10, 2009
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 !Anonymous
October 16, 2009
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 serverAnonymous
October 19, 2009
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, SuhasAnonymous
October 26, 2009
Thanks Suhas , its been a great help ,Mail setup was successful . thanks Regards Ashish GuptaAnonymous
November 10, 2009
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...- Anonymous
April 22, 2016
The comment has been removed
- Anonymous
Anonymous
November 10, 2009
The comment has been removedAnonymous
December 21, 2009
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 solutionAnonymous
January 18, 2010
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 ). )Anonymous
January 18, 2010
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. SuhasAnonymous
February 10, 2010
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).Anonymous
February 16, 2010
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' ChitraAnonymous
February 18, 2010
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 SrinvasAnonymous
February 19, 2010
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 ChitraAnonymous
February 19, 2010
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:
- Are you logged on to SQL Server using Windows Authentication?
- 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.
Anonymous
February 19, 2010
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.Anonymous
February 20, 2010
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.Anonymous
February 21, 2010
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. SuhasAnonymous
February 24, 2010
I want to store email content to database. Is it possible. mail me at nsivaa at gmail dot comAnonymous
February 25, 2010
Hi masters i want to send mail using my exchange server when my job is complete so how to do it guide me.Anonymous
February 26, 2010
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. SuhasAnonymous
March 07, 2010
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!!!!!!!Anonymous
March 07, 2010
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, SuhasAnonymous
March 08, 2010
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!!!Anonymous
May 13, 2010
how to troubleshoot slow running queries through profilerAnonymous
May 13, 2010
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. SuhasAnonymous
October 14, 2010
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 ). )Anonymous
October 14, 2010
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.Anonymous
October 17, 2010
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.......Anonymous
October 17, 2010
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??????Anonymous
October 17, 2010
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.Anonymous
October 17, 2010
Hi Suhas, Thank you so much............Anonymous
October 18, 2010
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.Anonymous
October 19, 2010
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?Anonymous
February 05, 2011
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 .Anonymous
February 18, 2011
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 ¡¡¡¡Anonymous
April 06, 2011
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 itAnonymous
September 13, 2011
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! EfiAnonymous
September 13, 2011
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, SuhasAnonymous
November 04, 2011
@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 SaludosAnonymous
February 10, 2012
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.Anonymous
February 27, 2012
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). )Anonymous
March 07, 2012
It worked, thanks a lot. I think I was having problem with my mail server, bc it worked with my live account.Anonymous
April 09, 2012
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 !thanksAnonymous
May 06, 2012
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
- Anonymous
May 15, 2012
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
Anonymous
June 11, 2012
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 outAnonymous
July 24, 2013
Dear But i am not able to find the database mail option so what should i do for it?Anonymous
September 10, 2013
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). )"Anonymous
October 09, 2013
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). )Anonymous
October 28, 2013
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
- 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
Anonymous
November 04, 2013
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). )Anonymous
December 18, 2013
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 thanksAnonymous
December 18, 2013
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 thanksAnonymous
April 30, 2014
Ha! I just figure out my SMTP 587 port(465 not work), after 2 hours googling and trying.....Anonymous
May 22, 2014
Thanks sir,,,,,,,,,,,,this post is helpful for me........Anonymous
July 02, 2014
my sql server 2008 no dabasemail under management why? what will do?Anonymous
August 11, 2014
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 advanceAnonymous
September 04, 2014
In Profile i have used two account. I have faced issues that mail send twice some times. Can you help me for this ?Anonymous
September 27, 2014
Good!!!Thanks a lot. Its really works!!Anonymous
September 29, 2014
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.comAnonymous
November 05, 2014
For GMail SMTP access to work, you must enable so called "Less Secure Apps" feature at www.google.com/.../lesssecureapps If you dont do this, authentication attempt will be blocked by GMail.Anonymous
February 24, 2015
The comment has been removedAnonymous
May 17, 2015
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). )Anonymous
May 20, 2015
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 pleaseAnonymous
July 06, 2015
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)
- 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
Anonymous
July 21, 2015
Excellent Post, thank you very muchAnonymous
August 26, 2015
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.Anonymous
November 19, 2015
Very nice article and very descriptive language. Everything worked in one attemptAnonymous
December 15, 2015
Can we use gmail account with two step verification turned on?Anonymous
January 11, 2016
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 helpAnonymous
February 25, 2016
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.Anonymous
June 06, 2016
The comment has been removed