C#中的电子邮件代码问题 [英] Email code problem in C#

查看:92
本文介绍了C#中的电子邮件代码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我只是托管我的网站并创建了3封邮件并配置了Outlook并成功测试了传入和传出的邮件。



现在我只是在编码中使用了我的邮件但是通过编码如果我从gmail发送邮件到我的邮件info@website.com它收到了成功的邮件但是当我从我的邮件发送邮件到任何gmail时无法接收并收到错误。



我使用此代码,



Hi friends,

I just host my website and created 3 mails and configure to outlook and tested successfully incoming and outgoing mails.

now i just used my mail in coding but by coding if i sent message to my mail info@website.com from gmail it recieved message successfully but when i sent message to any gmail from my mail i cant recieve it and got error.

I used this code,

MailMessage mail = new MailMessage();
     mail.To.Add("aarohi_verma@gmail.com");
     mail.From = new System.Net.Mail.MailAddress("info@mywebsitename.com");
     mail.Subject = "Testing from code..!";

     mail.IsBodyHtml = true;
     mail.Body = string.Format("<html><body><b>Dear</b>" +
     " <font> Hello THis is for just testing </font><br/><br/>" +

     "</body></html>");

     SmtpClient smtp = new SmtpClient();
     smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

     smtp.Host = "smtp.gmail.com";
     smtp.Port = 587;

     smtp.UseDefaultCredentials = false;
     smtp.Credentials = new System.Net.NetworkCredential("info@mywebsitename.com", "my mail password from control panel");

     smtp.EnableSsl = true;
     smtp.Send(mail);







它给出的错误如下:






it gives error like:

 The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Source Error:


Line 49: 
Line 50:         smtp.EnableSsl = true;
Line 51:         smtp.Send(mail);
Line 52:     }
Line 53: }







如何解决?




how to solve it?

推荐答案

你试试这个吗?



要么:
smtp.Host =https://smtp.gmail.com;





smtp.EnableSsl = false;
Did you try this?

Either make:
smtp.Host = "https://smtp.gmail.com";

OR
smtp.EnableSsl = false;


HI AAROHI



你能检查一下你的SMTP.HOST。你有单独的邮件服务器。





Rgds

Jagadesh
HI AAROHI

Could you please check your SMTP.HOST. Are you having a Mail Server separately.


Rgds
Jagadesh


这篇关于C#中的电子邮件代码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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