如何在不使用Outolook的情况下通过C#发送邮件? [英] How Can I Send Mail By C# Without Using Outolook?

查看:120
本文介绍了如何在不使用Outolook的情况下通过C#发送邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在不使用outolook或交换网络服务的情况下通过c#发送电子邮件或阅读我的电子邮件?我应该提供我的邮件地址和密码,如果它们是正确的,让我发送/阅读我的邮件,如果我的邮件地址或密码不正确,不要让我做任何事情。我应该用C#。

i在互联网上搜索但我找不到好东西。它们是假邮件代码或创建邮件服务器代码。我需要通过c#登录yahoomail或gmail。

i want to know how can i send email or read my emails by c# without using outolook or exchange web service? i should give my mail address and password and if they were correct let me send/read my mails and if my mail address or password were not correct doesn't let me do any thing.codes should be in C#.
i searched on the internet but i could not find a good thing. they were fake mail codes or creating mail server codes. i need to log in to yahoomail or gmail by c#.

推荐答案

试试这个,希望它能帮到你。



for domain,更改端口号,n check。



Try this, hope it will help you.

for domain, change the port no., n check.

public void SendEmails(string ToEmail, string EmailSub, string EmailBody)
        {
            #region

            MailMessage mailer = new MailMessage();

            System.Net.NetworkCredential smtpauth = new System.Net.NetworkCredential();
            smtpauth.UserName = "npsproject300@gmail.com";
            smtpauth.Password = "project2013";

            SmtpClient smtp = new SmtpClient();
            smtp.UseDefaultCredentials = false;
            smtp.Host = "smtp.gmail.com";  //SMTP SERVER
            smtp.Credentials = smtpauth;
            smtp.Port = 587; // port no# 465 is gmail, 25 was domain dg.sa
            smtp.EnableSsl = true;

            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

            mailer.From = new MailAddress("npsproject300@gmail.com"); // Change it
            mailer.Subject = EmailSub;
            mailer.Priority = MailPriority.High;


            mailer.Body = EmailBody; // this is Body



            mailer.IsBodyHtml = true; // it is set to HTML 
            if (ToEmail.Contains(";"))
            {
                try
                {
                    string[] emails_ = ToEmail.Split(';');
                    for (int i = 0; i < emails_.Length; i++)
                    {
                        mailer.To.Add(new MailAddress(emails_[i]));
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                mailer.To.Add(new MailAddress(ToEmail)); //Receiver's Email address
            }

            smtp.Send(mailer);
            #endregion
<pre lang="text">





}




}


这篇关于如何在不使用Outolook的情况下通过C#发送邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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