发送邮件时出错 [英] error when sending mail

查看:69
本文介绍了发送邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我正在我的网站上发送邮件,但它给出了非常常见的错误.错误是``551此邮件服务器在从本地托管的域发送邮件之前需要身份验证''.我在所有网站上都使用相同的功能.我不知道问题出在哪里,是服务器造成的.
这是我的代码.

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.

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");

推荐答案

尝试此代码

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)
        {
           
        }


您必须先登录到邮件服务器,然后才能发送此电子邮件.
因此,请确保您已连接,认证并登录到该服务器.
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.


正如Abhinav所说,您需要登录到邮件服务器. 此处 [ ^ ]是有关操作方法的说明.
As Abhinav said, you need to be logged to the mail server. Here[^] is an explanation on how to do it.


这篇关于发送邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆