好吧,我已经完成了功课,甚至看了这个网站上的几个例子,都无济于事。我的程序旨在发送表单上填写的数据,并将其发送到电子邮件中。除SmptMailMessage消息外,其余代码均未显示任何错误。这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;

namespace FPSArrestReport
 {
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void btn1_Click(object sender, EventArgs e)
    {

        SmtpClient SmptMailMessage = new SmtpClient();
        SmptMailMessage mail = new SmtpMailMessage("smtp.gmail.com", 25); // error on this line
         \\on the SmptMailmessage

           //set the to address to the primary email
      mail.To.Add("[email protected]");

     //set the message type and subject and body
      mail.IsHtmlMessage = true;
      mail.Subject = "";
      mail.Body = "Hello world!";

    //send the email
      mail.Send();
      }

最佳答案

System.Net.Mail库中没有SmtpMailMessage(或SmptMailMessage)这类类型。看来您正在尝试创建SmtpClient实例来发送消息。也许您打算做类似的事情;

SmtpClient client = new SmtpClient("smtp.gmail.com", 25);

MailMessage mail = new MailMessage();
mail.To.Add("[email protected]");
client.Send(mail);


您在此处使用2个对象-SmtpMailClient(用于发送)和描述消息的MailMessage。

关于c# - C#中的错误:找不到类型或 namespace “SmptMailMessage”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12683203/

10-09 00:40