Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am using gmail id to send mail from database. It is working fine till yesterday, But when I start using same Id to send mail from C# code. The Database Alert mail is not working.
Error Message is:
Mail queued.

The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2014-06-05T08:30:00). Exception Message: Could not connect to mail server. (Attempted to read or write protected memory. This is often an indication that other memory is corrupt.).

Database Mail code is as below:
SQL
EXEC msdb.dbo.sp_send_dbmail
@profile_name ='Mail Profile Name', 
@body = 'test message',
@body_format ='HTML',
@recipients ='myid@gmail.com', 
@subject = 'TEST MAIL FROM DB' ;

The C# Code is as below:
C#
MailMessage mail = new MailMessage();
SmtpClient smtpC = new SmtpClient("smtp.gmail.com");  
mail.From = new MailAddress(fromMailId);
mail.To.Add(toMailId);
mail.Subject = "Subject";
mail.Body = "Message in html format";
mail.IsBodyHtml = true;
smtpC.Port = 587;
smtpC.Credentials = new System.Net.NetworkCredential(fromMailId, password);
smtpC.EnableSsl = true; 
smtpC.Send(mail);

Please help me to solve this, I am facing problem on live server.
Posted
Updated 15-Jun-14 23:43pm
v4
Comments
Richard MacCutchan 16-Jun-14 5:38am    
You need to provide more details than "not working".
[no name] 16-Jun-14 5:39am    
This is the error message I got it from log.
Message
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2014-06-05T08:30:00). Exception Message: Could not connect to mail server. (Attempted to read or write protected memory. This is often an indication that other memory is corrupt.).
Thanks buddy
Richard MacCutchan 16-Jun-14 5:46am    
That points to a problem somewhere in your code but impossible to guess where. You will need to use your debugger to trace it.
[no name] 16-Jun-14 5:48am    
There is no error message while executing this query. I am facing problem only with sql code. C# code is working fine, No issue with this.
Richard MacCutchan 16-Jun-14 6:15am    
Then you need to do some further analysis to discover why the SQL code is failing. The message you showed above is your starting point.

Take a look at this discussion. I believe it may solve your issue.
http://stackoverflow.com/questions/4677258/send-email-using-system-net-mail-through-gmail[^]
 
Share this answer
 
v2
The problem is on DATABASE Server they have enabled SSL. It is solved by the server management team when I raised ticket.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900