1

My intention is to send a mail from c# using outlook interop library.But the problem is the prod machine won't have outlook software installed in it.

  1. Is ther a way to send mail using c# without outlook installed?
  2. Even if it is intalled, will it require an account to be configured? 3.Can we specify the from address manually instead of accessing the outlook account?

Note: I am not going to use SMTP based email because the sent mails will not sync with the mail server.

Thanks

Jeyaganesh
  • 1,334
  • 5
  • 26
  • 48
  • 1
    Any reason why use outlook interop to send email? – ysrb Aug 19 '13 at 06:12
  • 1
    Not that I'm aware of, the whole idea of an interop is to access outlook and use it's functionality. It's kind of look a hook I suppose. You can use `http://msdn.microsoft.com/en-us/library/system.net.mail.aspx` instead though. Pretty much the same but you don't need Outlook to send mail. – Trent Aug 19 '13 at 06:14
  • Not specific but I want to track the sent items and can able to access it any time – Jeyaganesh Aug 19 '13 at 06:14
  • @filebuzz using system.net.mail is simply thro SMTP right? I wish to have using exchage server. – Jeyaganesh Aug 19 '13 at 06:16
  • @jeyaganesh Try this link; http://stackoverflow.com/a/865514/1222199 (First result when googling "C# access exchange server" by the way...) – Trent Aug 21 '13 at 01:00

2 Answers2

1

yes this is possible using C# alone. user does not need to install outlook in client machine.

C# provides a namespace called System.Net.Mail. This has all the classes required to send a mail from C#. It does not have any dependency with OutLook. Have a look below code snippet :

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();    
message.To.Add("jeet@abc.come");    
message.Subject = "This is the Subject line";    
message.From = new System.Net.Mail.MailAddress("From@XYZ");    
message.Body = "This is the message body";    
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("**yoursmtphost**");    
smtp.Send(message);

In place of "yoursmtphost" you can configure the Ip address of machine as well.

Hope this solves your query. Don't forget to mark answered if done.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Jeet
  • 91
  • 2
  • Hello, This uses SMTP but what I need is through exchage because the mails sent through SMTP are not synced with server.This is the main purpose – Jeyaganesh Aug 19 '13 at 06:22
1

You can easily use Gmail free SMTP Server and send Mail using your Gmail account :

            System.Net.Mail MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add("yourfriend@yahoo.com");

            message.Subject = "subject";
            message.From = new System.Net.Mail.MailAddress("yourgmailaccount@gmail.com");
            message.Body = "body";
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
            smtp.Credentials = new System.Net.NetworkCredential("yourgmailaccount@gmail.com", "yourgmailpassword");
            smtp.EnableSsl = true;

            smtp.Send(message);