English 中文(简体)
送电子邮件到C#?
原标题:Sending E-mail in C#?
  • 时间:2010-06-21 10:36:31
  •  标签:
  • c#

我正试图寄出邮件,但该守则引起错误,“拖延失败”

MailMessage MailMesaji = new MailMessage();
MailMesaji.Subject = "subject";
MailMesaji.Body = "mail body";
//MailMesaji.BodyEncoding = Encoding.GetEncoding("Windows-1254"); // Turkish Character Encoding
MailAddress mdrom = new MailAddress("amit.pandey@verydindai.com");
MailMesaji.From = mdrom;
MailMesaji.To.Add(new MailAddress("govind@verydindai.com"));

System.Net.Mail.SmtpClient Smtp = new SmtpClient();
Smtp.Host = "mail.verydindai.com"; // for example gmail smtp server
Smtp.EnableSsl = true;
Smtp.Port = 465;

Smtp.Credentials = new System.Net.NetworkCredential("amit.pandey", "1234567");
Smtp.Send(MailMesaji);

pl子告诉我解决办法吗? 以及是否有另一种解决办法告诉我?

最佳回答

I am write down a console application please try with this sample. with your credentials To address,From Address,Password,Body text

using System;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace TestingConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string to = "to@domain.com";
                string from = "from@gmail.com";
                string from_pwd = "mypassword";
                string subject = "Sample Mail testing";
                string body = "Wow this is testing body";
                MailMessage mM = new MailMessage();
                mM.From = new MailAddress(from);
                mM.To.Add(to);
                mM.Subject = subject;
                mM.Body = body;
                mM.IsBodyHtml = false;
                mM.Priority = MailPriority.High;
                SmtpClient sC = new SmtpClient("smtp.gmail.com");
                sC.Port = 587;
                sC.Credentials = new NetworkCredential(from, from_pwd);
                sC.EnableSsl = true;
                sC.Send(mM);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + " " + e.StackTrace);
            }
        }
    }
}
问题回答

mail是否使用不同的港口在违约25时进行倾斜?

http://mail.google.com/support/bin/answer.py?hl=en&answer=13287

 string to = "";
    string from = "";
    string from_pwd = "";
    MailMessage mM = new MailMessage();
    mM.From = new MailAddress(from);
    mM.To.Add(to);
    mM.Subject = subject;
    mM.Body = body;
    mM.IsBodyHtml = true;
    mM.Priority = MailPriority.High;
    SmtpClient sC = new SmtpClient("smtp.gmail.com");
    sC.Port = 587;
    sC.Credentials = new NetworkCredential(from, from_pwd );
    sC.EnableSsl = true;
    sC.Send(mM);

也许需要改变你重新连接的港口,我认为,如果能够使SSL发挥作用,就应当有465个或587个港口。

另外,如果你拥有一些可能受到干扰的AntVirus软件,也进行检查。 异常常见的情况是AV软件停止发送电子邮件的定制软件。 还有一些防火墙,不让你进入规定的港口。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签