Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,
I am sending mail on my website.But it is giving very unusual error.Error is '551 This mail server requires authentication before sending mail from a locally hosted domain'. I am using the same function on all websites.I Don't know where the problem is, is it from server.
This is my code.
C#
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
        //MailAddress mlAddrFrom = new MailAddress("info@dphinfotech.com");
        //MailAddress mlAddrTo = new MailAddress("info@dphinfotech.com");

        msg.From = "infodelhi@dphinfotech.com";
        msg.To = "infodelhi@dphinfotech.com";

        msg.Body = "<b>Query</b><br /><br /><br />Firstname: " + txtfirstname.Value + "<br /><br /><br />Lastname: " + txtlastname.Value + "<br /><br /><br />PhoneNo.: " + txtphone.Value +
            "<br /><br /><br />EmailAddress: " + txtemail.Value + "<br /><br /><br />Query: " + txtmessage.Value;
        msg.Subject = "Query";

        msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtsperver"] = "mail.real.co.in";
        //msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;
        //msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
        msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
        msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "query@real.co.in";
        msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "Real";
        System.Web.Mail.SmtpMail.SmtpServer = "mail.real.co.in";
        System.Web.Mail.SmtpMail.Send(msg);
        Response.Redirect("~/thank_you/index.html");
Posted
Updated 8-Aug-11 18:29pm
v2

try this code

string subject = "mention subject here";
        try
        {
            
            string emailTo = "email";
            string emailfrom="email";
            string body = "urbody";
            MailMessage objmail = new MailMessage(emailfrom, emailTo, subject,body);
 
 
            SmtpClient smtpclnt = new SmtpClient("smtp.gmail.com", 587);
            smtpclnt.DeliveryMethod = SmtpDeliveryMethod.Network;
 
            smtpclnt.UseDefaultCredentials = true;
            smtpclnt.EnableSsl = true;
            smtpclnt.Credentials = new System.Net.NetworkCredential("username", "password");
            smtpclnt.Send(objmail);
        }
        catch (Exception ex)
        {
           
        }
 
Share this answer
 
Comments
pawanvats 9-Aug-11 1:02am    
i have used your method sir but now it is giving error 'failure sending mail'
Pravinjas 9-Aug-11 1:19am    
try to use emailfrom as a gmail
You need to be logged into the mail server before you can send this email.
So make sure you are connected, authenticated and logged into this server.
 
Share this answer
 
As Abhinav said, you need to be logged to the mail server. Here[^] is an explanation on how to do it.
 
Share this answer
 
Comments
pawanvats 9-Aug-11 1:27am    
i have used this method also , but showing the same error
walterhevedeich 9-Aug-11 1:40am    
Have you tried putting the username and password as well? It seems from your code that you did not.
pawanvats 9-Aug-11 1:56am    
i have given. and i was giving it in my old code also
like this :-
msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "query@real.co.in";
msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "Real";

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