Jeyaganesh
Jeyaganesh

Reputation: 1354

Send mail using c# interop library without installing outlook client

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

Upvotes: 1

Views: 6789

Answers (2)

Sadegh Saati
Sadegh Saati

Reputation: 11

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("[email protected]");

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

            smtp.Send(message);

Upvotes: 1

Jeet
Jeet

Reputation: 91

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("[email protected]");    
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.

Upvotes: 1

Related Questions