Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
NetworkCredential smtpCreds = new NetworkCredential("xxx@gmail.com", "senderspassword");
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 25);
smtp.EnableSsl = true;
smtp.Credentials = smtpCreds;
//smtp.Credentials = new NetworkCredential(TextBox1.Text, TextBox1.Text);
MailMessage mail = new MailMessage("xxx@gmail.com", Emailtxt.Text, "Registration Details", bodytxt.Text);
smtp.Send(mail);

this code works well with ms access and sql 2005 database. But, when connected to remote sql2000 database error is shown at smtp.send(mail);

Error is:
remote connection not correct or not found
Posted
Updated 27-Jul-14 23:44pm
v2
Comments
Thanks7872 28-Jul-14 5:45am    
There is nothing to do with email code. Its error related to SQL Server.

1 solution

Please see the class Below. I used this class to send Emails from Gmail. Any how I cant see any connection issue with your Code. Please check the SQL Connection too. There may be firewall , Virus Guard blocks can be happen when sending using Email functions.

If you find any support from following code, plz marked as answered.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Web.Mail;
using System.IO;

namespace TestEmail
{
public class cEmail{

#region "Variable and properties"
private string mstrFrom;
private string mstrTo;
private string mstrCC;
private string mstrBCC;
private string mstrSubject;
private string mstrBody;
private Int32 mintMailBodyFormat;
public ArrayList mailAttachment;
public string mailAttach1;
private MailMessage mobjMail;

private string mstrError;

public string SendFrom{
get{
return mstrFrom;
}
set{
mstrFrom = value;
}
}

public string SentTo{
get{
return mstrTo;
}
set{
mstrTo = value;
}
}

public string SendCC{
get{
return mstrCC;
}
set{
mstrCC = value;
}
}

public string SendBCC{
get{
return mstrBCC;
}
set{
mstrBCC = value;
}
}

public string SendSubject{
get{
return mstrSubject;
}
set{
mstrSubject = value;
}
}

public string SendBody{
get{
return mstrBody;
}
set{
mstrBody = value;
}
}

public Int32 MailBodyFormat{
get{
return mintMailBodyFormat;
}
set{
mintMailBodyFormat = value;
}
}

public string Errordes{
get{
return mstrError;
}
set{
mstrError = value;
}
}

#endregion

#region "Send Email"
public void SendEmail()
{
mobjMail = new MailMessage();
mobjMail.From = "ISO TestEmail System <testemail.chesalon.com>";
try
{
string SenderName = System.Configuration.ConfigurationManager.AppSettings["SMTP:Sender"].ToString();
string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SMTP:From"].ToString();
mobjMail.From = SenderName + " <" + senderEmail + ">";
}
catch
{ }
mobjMail.To = mstrTo;
if (mstrCC != "") {
mobjMail.Cc = mstrCC;
}
if (mstrBCC != "") {
mobjMail.Bcc = mstrBCC;
}
mobjMail.Subject = mstrSubject;
mobjMail.BodyFormat = MailFormat.Html;


if (mailAttach1 != "" && mailAttach1 != null)
{
mobjMail.Attachments.Add(new MailAttachment(mailAttach1));
}
try
{
//adding username and password reading the system configuration file if exisits
SmtpMail.SmtpServer = System.Configuration.ConfigurationManager.AppSettings["SMTP:Server"].ToString();
if (System.Configuration.ConfigurationManager.AppSettings["SMTP:UseAuth"].ToString() == "1")
{
string email = System.Configuration.ConfigurationManager.AppSettings["SMTP:Email"].ToString();
string password = System.Configuration.ConfigurationManager.AppSettings["SMTP:Password"].ToString();
email = Encryption.DecryptSimple(email,"");
password = Encryption.DecryptSimple(password,"");
mobjMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
mobjMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", email);
mobjMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
}

string ServerPort = System.Configuration.ConfigurationManager.AppSettings["SMTP:ServerPort"].ToString();
mobjMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", ServerPort);

if (System.Configuration.ConfigurationManager.AppSettings["SMTP:UseSSL"].ToString() == "1")
{
mobjMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
}
else
{
mobjMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "false");
}

string url = System.Configuration.ConfigurationManager.AppSettings["TestEmailFOLDER"].ToString();
mstrBody = mstrBody.Replace("\n", "
");
mobjMail.Body = PopulateBody(mstrSubject,mstrBody, url);
SmtpMail.Send(mobjMail);
}
catch(Exception ex){
Errordes = ex.Message;
}
finally{
mobjMail = null;
}
}

private string PopulateBody(string title,string description, string url)
{
string body = string.Empty;
using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/EmailBody.htm")))
{
body = reader.ReadToEnd();
}
body = body.Replace("{Title}", title);
body = body.Replace("{Description}", description);
body = body.Replace("{URL}", url);
return body;
}

#endregion

}

}
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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