如何发送邮件,包括附件 [英] how to send mail including attachment

查看:79
本文介绍了如何发送邮件,包括附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我有一个html文本编辑器控件和一个文件上传控件,我需要使用从文件控件上传的html编辑器控件文本和附件文件直接发送邮件到xyz@abc.com... b / b


根据我之前的问题以另一种形式解释说我已将文件存储在服务器上然后发送邮件......但当我问我的客户时他们说我发送邮件的电子邮件xyz@abc.com o已配置为发送给它的任何内容都会自动存储在数据库中。



现在请帮助我如何开始我的编码我没有得到如何发送邮件与文件add..please

hi all i had a html text editor control and a file upload control where i need to send a mail directly to "xyz@abc.com" with the html editor control text and attachement file uploaded from file control...

as per my previous question in another form it was explained that i nned to store the file on server and then send mail...but when i asked my client they said that the email xyz@abc.com o which i was sending mail was configured such that anything send to it will store automatically in database.

now please help me in how to start my coding i am not getting how to send the mail with the file adding..please

推荐答案

创建静态类,然后将此方法添加到其中,只是从您的页面传递参数..



在解决方案资源管理器中创建文件夹附件,然后使用文件上传
create static class and then add this method to in it and just pass the parameters from your page..

create folder attachment in solution explorer and then
uploaded

附件控制保存在该文件夹中..

attachment using file upload control save in that folder..

Email em = new Email();







FileUpload1.SaveAs(Server.MapPath("~/Attachment/") + FileUpload1.FileName);







em.mail("smtp.gmail.com","xyz@gmail.com","password","aa@aa.com","body msg","subject","attachment name");










public void mail(string host, string fromaddress, string password, string toaddress, string body, string subject5, string attach)
    {
        SmtpClient smtp = new SmtpClient();
        MailMessage msg = new MailMessage();
        Attachment ament;
        try
        {
            smtp.Host = host;
            smtp.Credentials = new System.Net.NetworkCredential(fromaddress, password);
           
            msg.From = new MailAddress(fromaddress, fromaddress);
           
            msg.To.Add(toaddress);
           
            if (attach != "")
            {
               
                string path = Server.MapPath("~/Attachment/") + attach;
                ament = new Attachment(path);
                msg.Attachments.Add(ament);
            }
            msg.Subject = subject5;
         
            msg.IsBodyHtml = true;
            msg.Body = body;
            smtp.Send(msg);
        }
        catch (Exception ex)
        {
            Session["Mailerror"] = ex.Message;
        }
    }


如何开始我的编码我没有得到如何发送邮件添加



你为此烦恼谷歌吗?它只记录了几十万次! Google为C#发送带附件的电子邮件。
how to start my coding i am not getting how to send the mail with the file adding

Did you bother Googling for this? It's only been documented a couple of hundred thousand times! Google for "C# send email with attachments".


MailMessage mm = new MailMessage(abc@xyz.com)

{

Subject =,

Body =

};

mm.Attachments.Add(new Attachment(memoryStream,Attacment) .pdf));

SmtpClient mailClient = new SmtpClient(ConfigurationManager.AppSettings [HostName]。ToString(),25);

mailClient.DeliveryMethod = SmtpDeliveryMethod。网络;

mailClient.UseDefaultCredentials = true;

mailClient.Credentials = new NetworkCredential(ConfigurationManager.AppSettings [SenderId]。ToString(),ConfigurationManager.AppSettings [SenderPwd ] .ToString());



mailClient.Send(mm);
MailMessage mm = new MailMessage("abc@xyz.com")
{
Subject="",
Body =""
} ;
mm.Attachments.Add(new Attachment(memoryStream, "Attacment.pdf"));
SmtpClient mailClient = new SmtpClient(ConfigurationManager.AppSettings["HostName"].ToString(), 25);
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.UseDefaultCredentials = true;
mailClient.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["SenderId"].ToString(), ConfigurationManager.AppSettings["SenderPwd"].ToString());

mailClient.Send(mm);


这篇关于如何发送邮件,包括附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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