This project is read-only.

How can I send feedback mail from client machine?

May 25, 2011 at 6:27 PM

Hi,

I used MAPI to send message from client machine. It opens the default email client. But the default mail client fails to send the email. I found that the Email Type is same as my email address. But if I press Internet Type then it becomes SMTP. After making it SMTP it can send the mail properly. Is there any solution to this problem so that user do not have to fix the email type.

 

Thanks

May 25, 2011 at 8:43 PM
Edited May 27, 2011 at 5:47 AM

I could not found a better solution then using gmail smtp server.

Here is the code

using System;
using System.Net;
using System.Net.Mail;
using MefBasic.Threading;

namespace MusicAssistant.Helper
{
    public class EMailHelper
    {
        private const string SmtpServer = "smtp.gmail.com";
        private const string SmtpUsername = "UserName;
        private const string Password = "Password";
        private const string ContactEMail = "ContactAddress";

        public static void Send(string from, string subject, string message)
        {
            var worker = new BackgroundWorkerEx();
            worker.DoWork += (s, e) =>
                                 {
                                     try
                                     {
                                         var client = new SmtpClient(SmtpServer, 587)
                                         {
                                             Credentials = new NetworkCredential(SmtpUsername, Password),
                                             EnableSsl = true
                                         };
                                         var mailMessage = new MailMessage(from, ContactEMail, subject, message);
                                         mailMessage.ReplyToList.Add(from);
                                         client.Send(mailMessage);
                                     }
                                     catch (Exception ex)
                                     {
                                         e.Result = ex;
                                     }

                                 };
            worker.RunWorkerBlocked();
            
       }
    }
}