使用Windows表单应用程序发送附件和电子邮件 [英] Send attachment with Email using windows form application

查看:67
本文介绍了使用Windows表单应用程序发送附件和电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的winforms应用程序中,我创建了一个winform来发送EmailNow,我想用这个邮件附加一个文件(图像,文档或其他文件)并发送这个文件。我该如何执行此操作?代码在此处:

In my winforms application,i created a winform to send EmailNow i want to attach a file(image,doc or other file) with this mail and send this file. How can i perform this?Code is here:

using System.Net;
using System.Net.Mail;

private void button1_Click(object sender, EventArgs e)
        {
             try
            {
                
                string idfrom = textBox1.Text;
                String password = textBox2.Text;
                String idto = textBox3.Text;
                string msg = richTextBox1 .Text ;
                string sub = textBox4.Text;
                var smtp = new SmtpClient();
                {
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential(idfrom,password);
                    smtp.Timeout = 20000;
                }
                smtp.Send(idfrom, idto, sub , msg);
                MessageBox.Show("Message has been sent");
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message );
            }        
        }



谢谢


Thanks

推荐答案

查看这些



C#Winforms :发送带附件的电子邮件 [ ^ ]



使用C#在Win窗体中发送带附件的邮件 [ ^ ]



使用来自C#Windows的附件发送电子邮件使用Gmail SMTP的应用程序 [ ^ ]



问候..
See these

C# Winforms: Sending an email with attachment[^]

Sending Mail With Attachment in Win Forms Using C#[^]

Send Email with attachments from C# Windows application using Gmail SMTP[^]

Regards..


这篇关于使用Windows表单应用程序发送附件和电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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