为字符串的电子邮件创建自定义文件附件 [英] Create a custom file attachment for an email from a string

查看:102
本文介绍了为字符串的电子邮件创建自定义文件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是从字符串文件创建邮件附件,并给出自己的自定义扩展名。

What I want to do is to create a mail attachment from a string file and give it my own custom extension.

    public void CreateAttachment(string encryptedString, string fileName)
    {
        mail.Attachments.Add(Attachment.CreateAttachmentFromString(encryptedString, fileName));
    }

我想创建一个.bzk文件,它将被打开稍后移动Android应用程序。我该如何做?我知道有不同的构造函数,你可以看到这里!

I want to create a ".bzk" file and it's gonna be opened in a mobile Android application later. How do I do this? I know there are different constructors as you can see here!

我不知道我不得不使用什么构造函数,甚至尝试不同的MIME类型和编码后,它将无法正常工作。任何人都可以告诉我怎么做?

I do not know what constructors I have to use and even after trying different MIME types and Encodings, it won't work. Can anyone tell me how to do this?

编辑:

我已经解决了我的问题。这是我的解决方案:

I've solved my problem. Here is my solution:

public void CreateAttachment(string encryptedString, string fileName)
    {
        MemoryStream ms = new MemoryStream(
            ASCIIEncoding.ASCII.GetBytes(encryptedString)
        );

        Attachment = new Attachment(ms, new ContentType("text/bzk"));
        Attachment.Name = fileName + ".bzk";

        mail.Attachments.Add(Attachment);

    }


推荐答案

我解决了我的问题。这是我的解决方案:

I've solved my problem. Here is my solution:

public void CreateAttachment(string encryptedString, string fileName)
{
    MemoryStream ms = new MemoryStream(
        ASCIIEncoding.ASCII.GetBytes(encryptedString)
    );

    Attachment = new Attachment(ms, new ContentType("text/bzk"));
    Attachment.Name = fileName + ".bzk";

    mail.Attachments.Add(Attachment);

}

这篇关于为字符串的电子邮件创建自定义文件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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