Reputation: 1354
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.
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
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
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