gpt4 book ai didi

c# - C# : The type or namespace 'SmptMailMessage' could not be found 错误

转载 作者:行者123 更新时间:2023-11-30 20:04:37 25 4
gpt4 key购买 nike

好吧,我已经做了功课,甚至看了这个网站上的几个例子,但都无济于事。我的程序旨在发送在表格上填写的数据,并将其发送到电子邮件。除了 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("xxx@abc.com");

//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("xxx@abc.com");
client.Send(mail);

您在这里使用了 2 个对象 - 一个 SmtpMailClient(用于发送)和一个描述消息的 MailMessage

关于c# - C# : The type or namespace 'SmptMailMessage' could not be found 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12683203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com