本文介绍了使用C#、. NET 3.5发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好...

我正在研究INTRANET MAILING SYSTEM的项目,但是在发送邮件时,我的邮件被卡在了队列中,而不是进入MAILBOX.

实际上,我仅将系统用作服务器(即本地主机)来发送和接收邮件.

还有1件事,我想问的是,我的域名就像[email protected]一样,那么我应该在邮件的收件人部分写什么而不是GMAIL?

我需要安装任何外部服务器或类似的东西吗?

您能建议我如何解决此问题吗!!

Hello...

I am working on the project of INTRANET MAILING SYSTEM but while sending the mail my mail messages are getting stuck in the QUEUE rather going to the MAILBOX.

Actually I am using my system only as the server i.e. localhost for sending and receiving the mail messages.

And 1 more thing I would like to ask that what would be my domain name just like [email protected], then what should I write instead of GMAIL in the addressee part of the mail?

Do I need to install any external server or anything like that?

Can you suggest me how to sort out this problem!!!

推荐答案



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

public void CreateUser()
{
//BC_GmailSender is the method in my business layer

StringBuilder message = new StringBuilder();
message.Append(BC_GmailSender.GetMessage(13)); //The message that says "you have successfully registered"
message.AppendLine(BC_GmailSender.GetMessage(8) + " " + cust_id); //"Username"
message.AppendLine(BC_GmailSender.GetMessage(9) + " " + password); //"Password"

NetworkCredential loginInfo = new NetworkCredential("[email protected]", "your_password");
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("[email protected]");
            msg.To.Add(new MailAddress(email)); //The email address that the customer entered, a string
            msg.Subject = "Whatever subject";
            msg.Body = message.ToString();
            msg.IsBodyHtml = true;

            //Every email needs an smtp client
            //To use the Gmail smtp client:
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);
}


这篇关于使用C#、. NET 3.5发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 05:25