Can you invoke mail from Epicor?

What I’m trying to do is have a button which when pressed will clear out a field then bring up Mail (Outlook or whatever) for the user to input the body, then click send. The From would be specified already. I can probably do this with some ugly code from inside Epicor, but it would be nice if Epicor could just pass the MailTO parameter (as in MailTo:). I know Windows can do this in Excel and such, but can Epicor invoke it?

You can set a main menu item to launch an external process, and then code a button to execute that main menu item.

1 Like

Running outlook.exe /c ipm.note from a command line (or Window’s Run dialog), launches a new blank email message.

I’d bet there are command line options for including the values for fields like: TO:, CC:,Subject, etc…

And there are topics on her for launching an external process without having to use a menu item. Especially since the menu item might not allow passing parameters.

edit

found the following to include TO:,Subject: and body.
outlook.exe /c ipm.note /m someone@microsoft.com&subject=subject%20test&body=Email%20body%20test

edit #2

That doesn’t exactly work. It includes everything as part of the TO:
image

1 Like

I will look more into this, thank you :slight_smile: I’ll mark it as solved if I can figure it out. We just need the one or two people using the screen to be able to start an email chain, and they aren’t very technical people, so copy and paste really won’t work for them.

1 Like

And the web way is to create an HTML mailto link. This will pull up whatever email client defined so it will work with Outlook, Outlook Online (365), Gmail, whatever is defined as the default email client for Internet links.

2 Likes

I think that’s the way I’d prefer to do it, I can’t count on a specific location for Outlook. Plus I know some people (myself for example) that don’t use it :slight_smile:
It’s too bad I can’t just create the link in Epicor itself to send the mail with a click. I can probably make a fixed page and keep overwriting it with a new mailto: but it’s still kind of clunky that way. Requiring 2 clicks to open the Email instead of one.

Really? I think there’s some people on here who can do that…

If I type IExplore.exe at the command prompt, it doesn’t find it. I would guess you would need to have that in the PATH before that would work.

A long time ago @josecgomez did a post on printing to pdf and emailing in E9. It used the outlook interop, old school now I guess, but it worked.

Epicor already has this functionality with something called Document Sender. They acquired it with the DotNetIT acquisition and I was always under the impression that it was written by @Edge himself. It would be awesome for them to update this for their Kinetic UI…

As per Microsoft, IExplorer should be removed from every windows system (security issues). It’s been replaced with Edge. If your computer is new-ish, it probably only has edge.

1 Like

@MLamkin - Turns out to be super simple…

private void btnMail_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		string s = "mailto:ckrusen@matcor.com";	//TO:
		s = s + "?subject=This is the subject";
		s = s + "&cc=someone_else@example.com";
		s = s + "&body=This is the body.";

		// replace spaces with `%20`.  
		// Do the same for other characters that would smurf a URL (like `&`)
		s = s.Replace(" ","%20");  that are
		System.Diagnostics.Process.Start(s);
	}

And that invokes the default email client. It will even launch the new mail message if the client isn’t open (at least it does for Outlook 2016)

3 Likes

You can actually just use start.exe to open a link in your preferred web browser. That also includes mailto links. So, in C# that will be:

System.Diagnostics.Process.Start(@"mailto:this.address@this.site.com");

EDIT: I posted at the same time as Calvin here it seems. This is the same solution. If I can give you one word of advice, it’s to avoid string concatenations for this. It’s very slow for long strings, and there’s always a risk of malformed strings. Instead use string.Format(), or at the very least a StringBuilder:

var link = string.Format("mailto:{0}?subject={1}&cc={2}&body={3}", addressTo, subject, cc, body);

Also, to escape your URL characters, use System.Web.HttpUtility.UrlPathEncode(string), or System.Net.WebUtility.UrlPathEncode(string) if you don’t have System.Web available.

1 Like

UrlEncode() will convert spaces to pluses (Hello World to Hello+World).

Causing the email to be auto-filled like:

image

UrlPathEncode() will convert the non-compliant characters to use the %+ASCII (Hello World to Hello%20World)

And I’m not sure if escaping the whole “URL” is proper.

If I want Subject to be This&That, the URL (pre- any escaping) would be:
mailto:me@test.com&?subject=This&That&body=Hello World

UrlEncode() changes that to
mailto%3Ame%40test.com%26%3Fsubject%3DThis%26That%26body%3DHello+World

You probably want to escape each component (To, Subject, Body, etc…), and then combine them

sting adressTo="me@test.com";
string subject = "This&That";
string cc = "";
string body="Hello World";

var link = string.Format("mailto:{0}?subject={1}&cc={2}&body={3}", addressTo, UrlEncode(subject), cc, UrlEncode(body));
1 Like

Thanks to everyone on this thread for the help :slight_smile: It’s working great.