这段代码有什么问题?该程序旨在复制文件并将其通过电子邮件发送到电子邮件地址,但事实并非如此。
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;
using System.Net.Mail;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
public void email_send()
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("your mail@gmail.com");
mail.To.Add("to_mail@gmail.com");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("your mail@gmail.com", "your password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
}
这显示了以下编译器错误:
- 预期的类、委托、枚举、接口或结构
- 预期的类、委托、枚举、接口或结构
- 预期的类、委托、枚举、接口或结构
- 预期的类、委托、枚举、接口或结构
- 预期的类、委托、枚举、接口或结构
- 预期的类、委托、枚举、接口或结构
- 类型或命名空间定义,或预期文件结尾预期类、委托、枚举、接口或结构
我能做些什么呢?