Exemple #1
0
        /// <summary>
        /// Converts the SRC attribute of IMG tags into embedded content ids (cid).
        /// Example: &lt;img src="filename.jpg" /&lt; becomes &lt;img src="cid:unique-cid-jpg" /&lt;
        /// </summary>
        private void ReplaceImgSrcByCid()
        {
            var fileList = new List <string>();

            _tagHelper.TagName = "img";

            foreach (string element in _tagHelper.StartTags)
            {
                string srcAttr = _tagHelper.GetAttributeValue(element, "src");
                if (string.IsNullOrEmpty(srcAttr))
                {
                    continue;
                }

                try
                {
                    // this will succeed only with local files (at this time, they don't need to exist yet)
                    string filename = MakeFullPath(MakeLocalPath(srcAttr));
                    if (!fileList.Contains(filename))
                    {
                        string contentType = Mime.GetContentType(new FileInfo(filename));
                        var    lr          = new LinkedResource(new MemoryStream(new ASCIIEncoding().GetBytes(string.Empty)), contentType);
                        _inlineAtt.Add(new FileAttachment(filename, MakeCid(string.Empty, lr.ContentId, new FileInfo(filename).Extension),
                                                          contentType));
                        _tagHelper.ReplaceTag(element,
                                              _tagHelper.SetAttributeValue(element, "src",
                                                                           MakeCid("cid:", lr.ContentId, new FileInfo(filename).Extension)));
                        fileList.Add(filename);
                        lr.Dispose();
                    }
                }
                catch
                {
                    continue;
                }
            }
        }
 /// <summary>
 /// Creates a new file attachment information
 /// </summary>
 /// <param name="content">Content for the attachment</param>
 /// <param name="displayName">Name and extension as the reader of the mail should see it (in case of inline attachments displayName is used for CIDs</param>
 public StringAttachment(string content, string displayName)
 {
     Content     = content;
     DisplayName = displayName;
     MimeType    = Mime.GetContentType(new FileInfo(displayName));
 }
Exemple #3
0
 /// <summary>
 /// Creates a new file attachment information
 /// </summary>
 /// <param name="fileName">Full path of the file </param>
 /// <param name="displayName">Name and extension as the reader of the mail should see it (in case of inline attachments displayName is used for CIDs</param>
 public FileAttachment(string fileName, string displayName)
 {
     Filename    = fileName;
     DisplayName = displayName;
     MimeType    = Mime.GetContentType(new FileInfo(fileName));
 }
 /// <summary>
 /// Creates a new file attachment information
 /// </summary>
 /// <param name="content">Content for the attachment</param>
 /// <param name="displayName">Name and extension as the reader of the mail should see it (in case of inline attachments displayName is used for CIDs</param>
 /// <param name="mimeType">Mime type of the file</param>
 public StringAttachment(string content, string displayName, string mimeType)
 {
     Content     = content;
     DisplayName = displayName;
     MimeType    = string.IsNullOrEmpty(mimeType) ? Mime.GetContentType(new FileInfo(displayName)) : mimeType;
 }
Exemple #5
0
 /// <summary>
 /// Creates a new file attachment information
 /// </summary>
 /// <param name="fileName">Full path of the file</param>
 /// <param name="displayName">Name and extension as the reader of the mail should see it (in case of inline attachments displayName is used for CIDs</param>
 /// <param name="mimeType">Mime type of the file</param>
 public FileAttachment(string fileName, string displayName, string mimeType)
 {
     Filename    = fileName;
     DisplayName = displayName;
     MimeType    = string.IsNullOrEmpty(mimeType) ? Mime.GetContentType(new FileInfo(fileName)) : mimeType;
 }