Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
In my application (.Net v2), I need to send mail facility.

Code as below

try
        {

            MailMessage mail = new MailMessage();
            mail.To = "me@me.net";
            mail.Cc = "me@rediffmail.com";
            mail.From = txtEmail.Text;
            mail.Subject = "Comment";
            mail.Body = "Comment" + ":" + txtComment.Text + " " + " " + "Address" + ":" + txtAddress.Text + "  " + "  " + "Phone" + ":" + txtPhone.Text;
            mail.BodyFormat = MailFormat.Html;
            SmtpMail.SmtpServer = "webmail.me.net";
            SmtpMail.Send(mail);
            lblDisplay.Text = "Successfully Posted";
        }
        catch (Exception ex)
        {
            lblDisplay.Text = ex.Message;
        }


I uploaded it but it shows an error.

The message could not be sent to the SMTP server.
The transport error code was 0x800ccc6a.
The server response was 451 ESMTP MailEnable Service temporarily refused connection at 07/30/10 10:40:50 from IP (67.228.202.164) because the server is too busy.


I don't know the problem or the solution.
Posted
Updated 29-Jul-10 23:55pm
v2
Comments
Dalek Dave 30-Jul-10 5:55am    
Edited for Readability and Code Block.

please add also smtp port. by default smtp port is 25 but check for different if your mail server have different smtp port. Please check also SMTP services is installed or not on web server. if it is installed then check it for running or not.


hope it will help you.
 
Share this answer
 
v2
 
Share this answer
 
Hi,

Please verify this link

http://aspalliance.com/149

Regards
Nageswaran
aspnetforum.blogspot.com
 
Share this answer
 
You can use if you want...

using System.Net.Mail;
using System.Net.Mime;

public class EmailObjects
{
public string From;
public string DisplayName;
public string To;
public string CC;
public string BCC;
public string ReplyTo;
public string Subject;
public MailPriority Priority;
public bool IsBodyHtml;
public string Body;
//MailAddress is not serialiazable
//AttachmentCollection is not serialiazable
}

public string SendMail(EmailObjects email)
{
SmtpClient SmtpServer=null;
MailMessage mail = null;
try
{
SmtpServer = new SmtpClient();
SmtpServer.Credentials = new
System.Net.NetworkCredential("ursenix@gmail.com", "password");
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
mail = new MailMessage();
mail.From = new MailAddress(email.From.ToString(),
email.DisplayName.ToString(), System.Text.Encoding.UTF8);

string[] To = email.To.Split(',');
string[] CC = email.CC.Split(',');
string[] BCC = email.BCC.Split(',');

foreach(string _to in To)
mail.To.Add(_to);

foreach(string _cc in CC)
mail.CC.Add(_cc);

foreach(string _bcc in BCC)
mail.Bcc.Add(_bcc);

mail.ReplyTo = new MailAddress(email.ReplyTo);
mail.Subject = email.Subject;
mail.Priority = email.Priority;
mail.IsBodyHtml = email.IsBodyHtml;
mail.Body = email.Body;

Attachment MyAttachment = new Attachment(@"F:\SenthilPlay.Jpg",
MediaTypeNames.Image.Jpeg);
mail.Attachments.Add(MyAttachment);

LinkedResource logo = new LinkedResource(@"F:\SenthilFoto.JPG");
logo.ContentId = "Logo";
string htmlview;
htmlview = "<html><body><hr/><table border=2>"+
"<tr width=100%>" +
"<td><img src=cid:Logo alt=SenthilHome /></td>" +
"<td>" +
"<table border='0'>" +
"<tr><td><b>Senthil Home Research Center</b></td></tr>"+
"<tr><td>Email: Click <a
href='mailto:ursenix@gmail.com'>here</a> to email me</td></tr>" +
"<tr><td>My Blog: <a href='http://ursenix.blogspot.com'>View My Blog</a></td></tr>" +
"<tr><td>Linked-in: <a href='http://www.linkedin.com/in/ursenix'>View My Blog</a></td></tr>" +
"<tr><td><u><b>Album:</b></u></td></tr>" +
"<tr><td><a href='http://picasaweb.google.com/ursenix'>View My Picasa Web Album</a></td></tr>" +
"<tr><td><a href='http://www.flickr.com/photos/ursenix'>View My Flickr Web Album</a></td></tr>" +
"</table>" +
"</td>" +
"</table><hr/></body></html>";

AlternateView alternateView1 = AlternateView.CreateAlternateViewFromString(email.Body + htmlview, null, MediaTypeNames.Text.Html);

alternateView1.LinkedResources.Add(logo);
mail.AlternateViews.Add(alternateView1);

SmtpServer.Send(mail);
return "Mail Sent Successfully";
}
catch (SmtpException ex)
{
return ex.Message.ToString();
}
}
 
Share this answer
 
The message could not be sent to the SMTP server. The transport error code was 0x800ccc6a. The server response was 451 See http://pobox.com/~djb/docs/smtplf.html."

This problem is because of Bare LF ie new line feed.

This error comes when you have a multline textbox and while tying in it you press enter.When you press enter it is repalced by "\r\n" in IE and "\n" in mozilla.

just add the following line of code.Lets say you have a string called msg

msg = msg.Replace("\r\n", "
"); //This is to solve this error in IE
msg = msg.Replace("\n", "
"); //This is to solve this error in //Firefox,mozilla

msg = msg.Replace(Environment.NewLine, "
");

If you still have any problems please feel free to send mail.
sandip.gend@gmail.com
 
Share this answer
 
v2

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