Community
Showing results for 
Search instead for 
Do you mean 
Reply

Send email through ACT! from MVC site C#

New Member
Posts: 19
Country: USA

Send email through ACT! from MVC site C#

Hey all,

 

I'm trying to figure out a way to accomplish something, and I can't think of a good way to start.  I am trying to get something similar to a mailto link (populate an email with dynamic information), from an MVC C# site without sending it (it needs to be doctored a bit).  I have this working by creating a mailto link for each item, and adding it to my View as a property of the model.  This works great, but I also need a copy of the email to be added for the contact in ACT!, and I can't think of a good way to do this. 

 

Does anyone have experience doing anything similar, or have a suggestion how I could do this another way?  I figure it'd be easy if I could fire a mailto link from a controller method, but I haven't found a way to accomplish it...

 

Thanks!

Mike

Employee
Posts: 1,163
Country: USA

Re: Send email through ACT! from MVC site C#

Hey Mike,

 

I don't have experience doing this myself. However if the goal is to get a copy of the mail in act and you already have the text from the body of the email, could you record it as a history item?

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 19
Country: USA

Re: Send email through ACT! from MVC site C#

Hi Matthew,

 

I think I'm actually going to change the way I'm working on it.  Instead of using the mailto, I'll create a view for mocking up the email, and then use the ACT send email logic similar to what's listed here:

 

http://community.act.com/t5/Sage-ACT-Developer-s-Forum/Compose-and-Send-Email-via-SDK/m-p/134632/hig...

 

Thanks for the suggestion though!

 

Once I have it working, I'll post my code...

 

Mike

Employee
Posts: 1,163
Country: USA

Re: Send email through ACT! from MVC site C#

Excellent, look forward to seeing it and thank you for contributing.

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 19
Country: USA

Re: Send email through ACT! from MVC site C#

I think I'm really close, but I'm not sure how to instantiate UIEmailManager... Here's what I'm trying to do:

 

Act.UI.Email.UIEmailManager aEmail = new Act.UI.Email.UIEmailManager();

ContactList contact = folderHelper.CheckActContact(key, ActContact);

StringCollection attachments = new StringCollection();
String file = FileToAdd;
attachments.Add(file);
            

if (aEmail.CanEmail() && aEmail.IsSystemsSetup())
    aEmail.SendEmailToContact(contact[0], Body, Subject, Act.Framework.Preferences.Enums.EmailCreateHistoryType.None, false, false, attachments, ToAddresses.ToArray());

return View("MyView");

 The problem is, the aEmail = new UIEmailManager gives me the error "The type 'Act.UI.Email.UIEmailManager' has no constructors defined.".  Does anyone know how to create a UIEmailManager object?

 

Thanks!

New Member
Posts: 19
Country: USA

Re: Send email through ACT! from MVC site C#

I got it...

 

I'll post the complete code once I'm done testing.

New Member
Posts: 19
Country: USA

Re: Send email through ACT! from MVC site C#

Ok, bear with me, it's a bunch of code (and it isn't pretty yet, just got it working):

 

A couple notes:

 1) ocfileinfo is a PDF FileInfo object

 2) CheckActContact returns either a 0 count ContactList if no user was found, or a specific contact based on an email address (ActContact), and a user/pass in a Dictionary (key).  To see how to create that method, use this:

http://community.act.com/t5/Sage-ACT-Developer-s-Forum/Fairly-new-to-ACT-Software-Developer-looking-...

 

 

            Act.Framework.ActFramework framework = new Act.Framework.ActFramework();
            ContactList contact = folderHelper.CheckActContact(key, ActContact);
            if (contact.Count() > 0)
            {
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                foreach (String to in ToAddresses)
                {
                    message.To.Add(to);
                }
                if (CCAddresses.Any())
                {
                    foreach (String cc in CCAddresses)
                    {
                        message.CC.Add(cc);
                    }
                }
                message.Body = Body;
                message.Subject = Subject;
                System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress("fromemail@emailserver.com");
                message.From = from;
                FileStream fStream = System.IO.File.OpenRead(ocfileinfo.FullName);
                System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(fStream, ocfileinfo.Name);
                message.Attachments.Add(attachment);
                message.Save(message, @"C:\test.eml");

                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtpserver.server.net", 80);
                smtp.Credentials = new System.Net.NetworkCredential("emailusername", "emailpassword");
                smtp.Send(message);

                String[] contactid = { contact[0].ID.ToString() };
                framework.LogOn(@"\\RemoteServer\database.pad", "Username", "Password");

                Boolean m = framework.Histories.AttachEmailToContact(contactid, @"C:\test.eml", Subject, DateTime.Now);
                framework.LogOff();
            }
            else
            {
                ViewBag.Authenticated = "Contact not found in ACT!.  Please verify the email and try again.";
                return View("SendEmail", model);
            }
            return RedirectToAction(MyMainViewName);

 

New Member
Posts: 19
Country: USA

Re: Send email through ACT! from MVC site C#

Oh, and one more note... the message.Save functionality (saving an email and specifying a filename/path), I found here:

http://www.codeproject.com/Articles/32434/Adding-Save-functionality-to-Microsoft-Net-Mail-Ma