好吧,我已经完成了我的作业,甚至在这个网站上看了几个例子,但没有用.我的程序旨在发送填写在表单上的数据,并将其发送到电子邮件.除了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();
}
Run Code Online (Sandbox Code Playgroud)
有一个在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);
Run Code Online (Sandbox Code Playgroud)
您在这里使用了2个对象 - 一个SmtpMailClient(用于发送)和一个描述该消息的MailMessage.
| 归档时间: |
|
| 查看次数: |
5575 次 |
| 最近记录: |