這段代碼有什麼問題?該程序旨在複製文件並通過電子郵件將其發送到電子郵件地址,但不是。編譯時出錯:「期望的類,委託,枚舉,接口或結構」
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 [email protected]");
mail.To.Add("[email protected]");
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 [email protected]", "your password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
}
這表明以下編譯器錯誤:
- 預期類,委託,枚舉接口,或結構
- 預期類,委託,枚舉接口,或結構
- 預期類,委託,枚舉,接口或結構
- 預期的類,委託,枚舉,接口或結構
- 預期的cl屁股,委託,枚舉,接口或結構
- 預期類,委託,枚舉,接口或結構
- 類型或命名空間定義或文件結束的預期 預期類,委託,枚舉,接口或struct
我該怎麼辦?