使用C#、. NET 3.5发送邮件 [英] sending mails using C#, .NET 3.5
问题描述
你好...
我正在研究INTRANET MAILING SYSTEM的项目,但是在发送邮件时,我的邮件被卡在了队列中,而不是进入MAILBOX.
实际上,我仅将系统用作服务器(即本地主机)来发送和接收邮件.
还有1件事,我想问的是,我的域名就像qaz@gmail.com一样,那么我应该在邮件的收件人部分写什么而不是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 qaz@gmail.com, 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!!!
推荐答案
您需要设置和配置SMTP服务器.从那里您可以使用服务器的地址/端口,届时您还应该拥有一个已注册的邮件域.
You need to have an SMTP server setup and configured. From there you can use the server''s address/port, by then you should also have a registered mail domain.
正如Mark所说的,无论是用于Intranet或Internet.
首先使该功能正常运行,然后使用普通的电子邮件客户端(例如Outlook或Thunderbird)进行测试.
当此方法有效时,使用System.Net.Mail
命名空间发送电子邮件应该是一件轻而易举的任务.
尼克
As Mark said, you need a working SMTP server, whether it is for an intranet or the internet.
Get this working first and test with a normal email client like Outlook or Thunderbird.
When this is working, it should be a trivial task to use theSystem.Net.Mail
namespace to send your email.
Nick
我为我的最后一年的项目做过类似的事情.
我的数据库中有一个表格,其中包含所有用户的电子邮件地址,另一个表格中有要显示的设置消息,例如:您的订单号为:",然后从我的应用中插入订单号.
我使用了一个stringbuilder,以便将电子邮件写成一个句子.您可以根据需要进行操作.
因此,在我的视图层中,我在用户注册页面中具有以下代码(因为已发送电子邮件确认注册:
I did a similar thing for my final year project.
I had a table in my database with all the users'' email addresses, and another one with the set messages i wanted to display eg: "Your order number is :" and i would insert the order number from my app.
I used a stringbuilder so that the email would be written as one sentence. You can manipulate it however you want.
So, in my view layer, i had the following code in the user registration page (since an email is sent to confirm the registration:
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("your_email@gmail.com", "your_password");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("your_email@gmail.com");
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发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!