我的代码纠错 [英] error correction for my code

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

问题描述

Hai,我是一名自由职业者,试图制作一个用于发送电子邮件的c#代码。我的编码如下所示。

但是一旦我运行我的代码,就会显示电子邮件发送因为没有实现502命令而失败。如果您能在下面更正我的代码,那将是您的好意。 。请帮助我。祝福你。

Hai, i am a freelancer trying to make a c# code for sending a email. I have coded as shown below.
But once i run my code, it shows that email sending has been failed because of not implementing 502 command.It would be kindful of you if you could correct my code below.Please help me.god bless you

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EASendMail; 

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SmtpMail oMail = new SmtpMail("TryIt");
            SmtpClient oSmtp = new SmtpClient();

            // Set sender email address, please change it to yours
            oMail.From = "faizel.shk@gmail.com";

            // Set recipient email address, please change it to yours
            oMail.To = "sumith.mani27@gmail.com";

            // Set email subject
            oMail.Subject = "test email from c# project";

            // Set email body
            oMail.TextBody = "this is a test email sent from c# project, do not reply";

            // Your SMTP server address
            SmtpServer oServer = new SmtpServer("smtp.gmail.com");

            // User and password for ESMTP authentication, if your server doesn't require
            // User authentication, please remove the following codes.            
            oServer.User = "faizel.shk";
            oServer.Password = "***********";

            // If your smtp server requires SSL connection, please add this line
             oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

            try
            {
                Console.WriteLine("start to send email ...");
                oSmtp.SendMail(oServer, oMail);
                Console.WriteLine("email was sent successfully!");
            }
            catch (Exception ep)
            {
                Console.WriteLine("failed to send email with the following error:");
                Console.WriteLine(ep.Message);
            }
            Console.Read();
        }
    }
}

推荐答案

try
       {
              string myEmailAddress = "A*********@gmail.com";
              string mypwd = "***************";
              string toEmailAddress = "xyz@abc.com";
              string subject = "Try to send mail";
              string mailbody = "this is try mail body";

           var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
           {
                  Credentials = new System.Net.NetworkCredential(myEmailAddress, mypwd),
                  EnableSsl = true
            };
           client.Send(myEmailAddress, toEmailAddress, subject, mailbody);


      }


       catch (Exception e1)
       {

         }







试试吧......


或SmtpServer oServer = new SmtpServer(smtp.gmail.com);



更改为此行



SmtpServer oServer =新的SmtpServer(smtp.gmail.com,587);
Or SmtpServer oServer = new SmtpServer("smtp.gmail.com");

Change to this line

SmtpServer oServer = new SmtpServer("smtp.gmail.com", 587);


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

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