如何在邮件中附加一个或多个文件. [英] how to attach one or more files in a mail.

查看:202
本文介绍了如何在邮件中附加一个或多个文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你能告诉我吗.我尝试过此代码..


can u tell me. i have try this code..

MailMessage myMess = new MailMessage("pradeep.mudiam@gmail.com","maddulapradeep@gmail.com");

//myMess.From = "info@achbiz.com";
myMess.Subject = "hi";
myMess.Body = "hghhh";

string Body = "jhgg";


AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");

string Fname = Path.GetFileName(FileUpload1.PostedFile.FileName);

string fServerDirPath = Server.MapPath("~/Upload//Document");

//Check Directory Exist or Not if Not Then Create New Directory

string fType = FileUpload1.PostedFile.ContentType;
Attachment objAttachment1 = new Attachment(FileUpload1.PostedFile.FileName);


int fSize = FileUpload1.PostedFile.ContentLength;

if (!Directory.Exists(fServerDirPath))
{
    Directory.CreateDirectory(fServerDirPath);
}

string fServerFileFullPath = fServerDirPath + Fname;

if (fType == "text/plain" || fType == "application/msword" || fType == "application/vnd.ms-excel" || fType == "application/vnd.ms-powerpoint")
{
    if (fSize <= 2097152) //Check Size for 2 MB
    {
        FileUpload1.SaveAs(fServerFileFullPath);

        Response.Write("File Successfully Uploaded");
    }
    else
    {
        Response.Write("Please Upload only Maximum 2 MB Size");
    }
}
else
{
    Response.Write("Please Upload only Txt/Doc/XLS/PPT File");
}
myMess.Attachments.Add(objAttachment1);

myMess.IsBodyHtml = true;

SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mySmtpClient.Host = "mail.payroll-taxes.info";
mySmtpClient.Port = 25;
mySmtpClient.Credentials = new NetworkCredential("support@payroll-taxes.info", "mnb1234");
mySmtpClient.Send(myMess);



[edit]已添加代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

签出此链接..

您可能会找到解决方案..
带有多个附件的ASP.NET电子邮件

根据Ur代码

只需创建更多附件对象
还有那个
Check Out This Link..

You May Get Solution..
ASP.NET email with multiple attachments

As Per Ur Code

Just Create More Attachment Object
And That One Also
myMess.Attachments.Add(objAttachment1);
myMess.Attachments.Add(objAttachment2);


尝试指定 ContentType [ ^ ]-目前,您正在filename作为字符串而不是文件本身.您可能还需要使用Server.MapPath方法来正确定位文件.
Try specifying the ContentType[^] - at the moment you are attaching the filename as a string, rather than the file itself. You may also need to use the Server.MapPath method as well in order to locate the file properly.


这篇关于如何在邮件中附加一个或多个文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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