Coder Social home page Coder Social logo

axuno / mailmergelib Goto Github PK

View Code? Open in Web Editor NEW
109.0 12.0 33.0 10.28 MB

MailMergeLib is a mail message client library which provides comfortable mail merge capabilities for text, inline images and attachments, as well as good throughput and fault tolerance for sending mail messages.

License: MIT License

C# 99.51% HTML 0.48% Batchfile 0.01%
smtp mime mail email merge template netcore netstandard dotnet-framework

mailmergelib's People

Contributors

axunonb avatar phnxnhp avatar timhill-iress avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailmergelib's Issues

Error wheny trying to use http image in html template

When I want to use an image by referencing it by http(s), I get an NotSupportedException error. It seems that it still wants to resolve an http:// image to a file:// image.
Stacktrace:

bij System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
bij MailMergeLib.Tools.MakeFullPath(String basename, String filename)
bij MailMergeLib.HtmlBodyBuilder.ReplaceImgSrcByCid()
bij MailMergeLib.HtmlBodyBuilder.GetBodyPart()
bij MailMergeLib.MailMergeMessage.BuildTextMessagePart(Object dataIteam)
bij MailMergeLib.MailMergeMessage.GetMimeMessage(Object dataItem)

Don't enforce ContentEncoding.SevenBit wtih pure 7bit content

When using MailMergeLib I'm seeing some odd issues where occasionally a dot will go missing from the email content once it's received by the recipients.

This often manifests as broken links or images due to a dot in the URL is missing.

With some research it appears that the issue is to do with something called "dot stuffing".

To allow all user composed text to be transmitted transparently, the following procedures are used:

  1. Before sending a line of mail text, the SMTP client checks the first character of the line. If it is a period, one additional period is inserted at the beginning of the line.
  2. When a line of mail text is received by the SMTP server, it checks the line. If the line is composed of a single period, it is treated as the end of mail indicator. If the first character is a period and there are other characters on the line, the first character is deleted.

See http://tools.ietf.org/html/rfc5321#section-4.5.2

All I can find on Google is people suggesting to use "Quoted Printable" encoding instead of whatever I'm using, however I already have the following set on the config of the message:

mailMergeMessage.Config.TextTransferEncoding = ContentEncoding.QuotedPrintable;

Looking into the repository a little it looks like you may be defaulting the encoding to 7-bit instead:

                ContentTransferEncoding = Tools.IsSevenBit(DocHtml)
                    ? ContentEncoding.SevenBit
                    : TextTransferEncoding != ContentEncoding.SevenBit
                        ? TextTransferEncoding
                        : ContentEncoding.QuotedPrintable,

https://github.com/axuno/MailMergeLib/blob/78e2336dfa18f3791ad89ca7ad4f506091082792/MailMergeLib/HtmlBodyBuilder.cs Line 98

I may be way off with this, but it seems that I am setting the message to use QuotedPrintable but still getting the dot stuffing issue.

Any ideas?

Error: 'MailMergeMessage' does not contain a definition of 'Deserialize'

Hi there!

Your lib looks good, it has almost all the features that I would like to see. One of the functions I would like to use is the 'templating' but only to store the plain and html code in xml files. I like the idea that e-mail layouts are separated from the controllers.

But, when I tried your example code in the Wiki about deserialisation, the error as mentioned in the title came up. Currently I have NuGet version 5.2.0.1 installed, maybe NuGet needs a new version to include the latest features?

Thanks in advance!
Joey

JSON as a datasource

Has anyone been able to get this library working using a WebApi Controller that accepts a dynamic object/payload and passes it on to MailMergeSender.Send? On my dto.Payload, I have tried accepting a dynamic, an ExpandoObject, an object, a Dictionary<string,string>, and additionally I have tried casting all of these to object and always produces the same error. The controller accepts the request just fine, and I can access and see the variables correctly when setting a breakpoint and using the immediate window.

It works just fine if I manually pass an object that I create in the code (ie: at compile time) such as:
new { ProjectId = "123", ProjectName = "hi" }

But with a dynamic object generated at runtime, none of the functionality seems to work. This may be a bug in SmartFormatter, since if I try to pass the same object to a basic Smart.Format call, it also does not work.

var message = new MailMergeMessage() { Config = settings.MessageConfig };
message.Subject = "Subject - Project ID: {ProjectId}";
message.HtmlText = "Body - Project Name: {ProjectName}";

_sender.Send(message, emailRequestDto.Payload);

VariableException: Variable(s) for placeholder(s) not found: {ProjectId}, {ProjectName}

I am building a micro service that accepts email requests using templates already sent to the service. The payload is completely dynamic and specific to each consumer and their template. Is it possible to use this library for this purpose?

System.IO.IOException when trying to delete a file that was used as an attachment

Hi,

I seem to have trouble deleting attachments after sending an email.

After .Send I am calling MailMergeMessage.GetMimeMessage so that I can save the mime message to a directory of sent items.

I then try clear up some temp files (the attachments), but i get an exception that another process has the file in use.

I get the error when calling MailMergeMessage.GetMimeMessage regardless of whether I call .WriteTo()

I'm disposing of the sender, and setting the MailMergeMessage to null/nothing, any ideas?

thanks

Error in GetMimeMessage

Hi getting the mime message of an html like:

<html>
<head>
<script type="colorScheme" class="swatch active">
{"name":"Default","bgBody":"333333","link":"7E8564","color":"AAAAAA","bgIte=
m":"ffffff","title":"444444"}</script>
</head>
<body>
<p>Hello world!</p>
</body>
</html>

cause an index out of bound exception.
Exception occur in HtmlBodyBuilder.cs, method GetBodyPart().
By changing the following line:
foreach (var element in _htmlDocument.All.Where(e => e is IHtmlScriptElement))
in

var scriptsElements = _htmlDocument.All.Where(e => e is IHtmlScriptElement).ToList();
// remove all Script elements, because they cannot be used in mail messages
foreach (var element in scriptsElements)

everything works correctly.
Hope this could be helpful for next release.

Status?

What is the status of this library? I've spent an entire day trying to get it to compile and run on VS 2015, to no avail. Should I be using the codeproject version? :)

Btw, I downloaded the zip yesterday, rather than using the GitHub protocol (I'm new to GitHub). Maybe the zip isn't synchronized?

Not compatible with SmartFormat v3.0

MailMergeLib v5.8
SmartFormat v3.0
Framework v4.8

MailMergeMessage mmm = new MailMergeMessage("Subject", "Message");

Gets exception "Method not found: 'Void.SmartFormat.SmartFormatter..ctor()'

Screen-2022-05-12_13-38-36

Tools.IsFullPath returns false for linux paths

While attempting to use MailMergeLib to send emails with dotnetcore on linux I get a failure.

'Building of message failed with one or more exceptions. See inner exceptions for details.'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception System.IO.DirectoryNotFoundException : 'Config.FileBaseDirectory' is not a full path.

It doesn't seem possible to work around this on linux as Tools.IsFullPath either returns false as the path isn't a valid looking linux path or because the root returned from Path.GetPathRoot(path) is only ever 1 character '/'

This is the code that seems too harsh for a linux path

if (pathRoot.Length <= 2) // Accepts X:\ and \UNC\PATH, rejects empty string, \ and X:
return false;

Streams for HTML inline image files are not disposed after sending a message

I use NuGet package version 5.2 with VS2015 on W7 64bit

After calling Send method mail is sent correctly, but file img.png is locked and can't be deleted while application is running.

My code example:

using (var mmm = new MailMergeMessage("subject"))
{
    mmm.HtmlText = "<html><body><img src=\"file:///C:/img.png\" alt=\"\"></body></html>";

    mmm.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.From, "[email protected]"));
    mmm.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.To, "[email protected]"));

    using (var mms = new MailMergeSender())
    {
        mms.Config.MaxNumOfSmtpClients = 1;
        mms.Config.SmtpClientConfig[0].MessageOutput = MessageOutput.SmtpServer;
        mms.Config.SmtpClientConfig[0].SmtpHost = "mail.com";
        mms.Config.SmtpClientConfig[0].SmtpPort = 587;
        mms.Config.SmtpClientConfig[0].NetworkCredential = new Credential("user", "password");
        mms.Config.SmtpClientConfig[0].MaxFailures = 3;

        mms.Send(mmm, (object)new Dictionary<string, object>());
    }
}

Performance benchmarks?

I have a client that has registered members and sends newsletters on a regular basis. These can be sent to anywhere between 1,000 and 100,000 subscribers depending on the segmentation.

Can you provide any benchmarks for how fast MailMergeLib could get through, for example, 50,000 emails?

They would all be the same content with the exception of a few personalizations such as recipient name, email, etc.

The SMTP server would be a well-known service such as SendGrid or MailGun.

Thanks

Format or parse error should not throw exception unless ErrorAction.ThrowError is set

I'm using the following config...

            mailMergeMessage.Config.SmartFormatterConfig.FormatErrorAction = ErrorAction.MaintainTokens;
            mailMergeMessage.Config.SmartFormatterConfig.ParseErrorAction = ErrorAction.MaintainTokens;
            mailMergeMessage.Config.SmartFormatterConfig.CaseSensitivity = CaseSensitivityType.CaseInsensitive;
            mailMergeMessage.Config.SmartFormatterConfig.ConvertCharacterStringLiterals = true;

Yet, when adding {RandomInvalidMergeTag} in the template mailMergeSender.Send(mailMergeMessage, recipients); throws an exception and fails to send the message.

Exception Message: Building of message failed with one or more exceptions.
Inner Exception Message: Variable(s) for placeholder(s) not found: {RandomInvalidMergeTag}

I thought that ErrorAction.MaintainTokens is supposed to ignore this error and just leave them as plain text in the sent message?

Edit: I get the same exception when using ErrorAction.Ignore too
Edit2: Also, shouldn't any error in the sending process call the OnMessageFailure or OnSendFailure events?

SmartFormat extension marked as internal

I want to use the TemplateFormatter but it is marked internal.
Please change it to public, the original source of SmartFormat also uses public for the extensions.

Events OnMessageFailure and OnSendFailure don't always fire as/when expected

Example, where OnMessageFailure will not fire before MailMergeSender throws an exception.

var mmm = new MailMergeMessage("Subject {dummy}", "Plain", "Html");
mmm.SmartFormatter.Settings.FormatErrorAction = ErrorAction.ThrowError;
mmm.SmartFormatter.Settings.ParseErrorAction = ErrorAction.ThrowError;
[...]
var mms = new MailMergeSender();
mms.OnMessageFailure += (sender, eventArgs) => { Console.WriteLine($"{eventArgs.Error.ToString()}"); };
try
{
    mms.Send(mmm, new Dictionary<string, string>() {{"key", "value"}});
}
catch (Exception e)
{
    Console.WriteLine(e);
}

At the same time, MailMergeSender should not throw a MailMergeMessageException for any parse or format errors, unless ErrorAction.ThrowError is set for FormatErrorAction or ParseErrorAction. See also issue #14

Same images files contained in several HTML img tags are not added properly

Hi axuno, nice work.

I'm working to migrate my project from ver 4.x to 5.

I faced an issue that if the html template contain an images in several place, from 2nd place it will not displayed correctly just like it was missing and only show a place holder.

I see the issue can be fix by duplicate the file, rename the 2nd file onward but it's not the good practice.

Hoping you can see anything not working as previous version here?

Not compatible with MailKit v3.0

After updating my nugets in an application that I've been using MailMergeLib for months without issue, it now gives me this exception error (see attached image).

Another application that uses MailMergeLib still works because I haven't updated nugets.

Both use lastest MailMergeLib v5.7.1 but the one that breaks uses MailKit v3.0 instead of MailKit v2.15.

It looks like MailKit 3.0 introduced a breaking change.

image

System.UriFormatException on MessageConfig.FileBaseDirectory with relative path.

When a relative path is used for the property FileBaseDirectory an exception System.UriFormatException: 'Invalid URI: The format of the URI could not be determined.' is thrown.

For example:

FileBaseDirectory = ".\Templates\Attachments"; //Throws exception
FileBaseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Templates\Attachments"); //Doesn't thow exception.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.