首页 > 解决方案 > 需要删除通过 asp.net 发送的电子邮件中的附件

问题描述

我编写了一个代码来通过 asp.net 在邮件中发送内联图像。

我在电子邮件中获取图像,但此外,我还获取 .bin 格式的图像附件。

我怎样才能摆脱这个附件?

此附件出现在所有电子邮件程序(mobile、owa、microsoft outlook 2016)中

附件名称为 AT00001.bin

下面是代码

    protected void UBR_HNC_Click(object sender, EventArgs e)
    {

        SmtpClient smtpClnt;
        MailMessage objMail;

        // Prepare Email  
        // Load Email Template from HTML File. 
        //String sHTMLbody = string.Empty;

        // Send Email
        // Create new Mail Object
        objMail = new MailMessage(); // Create new Mail Object
        objMail.From = new MailAddress("santoshkumar_g@abc.com");
        objMail.To.Add(new MailAddress("santoshkumar_g@abc.com"));

        objMail.Subject = "UBR Delivery HNC";

        objMail.AlternateViews.Add(Mail_Body());
        objMail.IsBodyHtml = true;


        // Open SMTP Connection to Mail Server and send email.
        smtpClnt = new SmtpClient();
        smtpClnt.Host = "10.98.134.29";
        smtpClnt.Port = Convert.ToInt16("25");
        smtpClnt.EnableSsl = false;
        smtpClnt.UseDefaultCredentials = false;

        smtpClnt.Send(objMail);

        smtpClnt.Dispose(); // Close the SMTP Mail server connection.
        objMail.Dispose(); // Clear the mail object
    }    

private AlternateView Mail_Body()    
{

    LinkedResource imageResource = new LinkedResource(Server.MapPath("~/images/UBR_Delivery_L2_HNCmail.png"));
    imageResource.ContentId = "HDIImage";
    string str = @"  
         <tr>  
                <td>  
                  <image src=cid:HDIImage  id='img' alt=''/>   
                </td>
            </tr>
        ";
    AlternateView AV =
    AlternateView.CreateAlternateViewFromString(str, null, MediaTypeNames.Text.Html);
    AV.LinkedResources.Add(imageResource);
    return AV;
}

标签: c#asp.netemail-attachments

解决方案


推荐阅读