2

I am writing a WPF (C#) application which takes feedback from user and send them through e-mail.

I want my program to send this mail to a fixed address without using any Desktop Mail Software (Outlook Express or Microsoft Outlook or Windows Mail or any other) & without opening any browser window.

In fact i want to send them undetected. That means user should not know about sending mails. (This is an optional requirement which can be ignored).

Anybody tell me how to do this. Thanks in advance.

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
  • possible duplicate of [Sending email in .NET through Gmail](http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail) – AndiDog Jan 15 '12 at 02:47
  • Code see other question. Note that you most probably will have to hardcode the mail password. Why don't you use a web service to receive the feedback? – AndiDog Jan 15 '12 at 02:48

5 Answers5

2

As an alternative to the standard System.Net.Mail.SmtpClient class provided by the framework, you could use something like DnSmtp. It allows your application to send emails directly without having to configure an SMTP server (it embeds all of the SMTP server 'magic'). If this really needs to run invisibly (assuming also without user configuration or having to hard code values) then this could be a worthwhile option.

M.Babcock
  • 18,753
  • 6
  • 54
  • 84
1

You should definitely try using

using System.Net.Mail;

This is a method you can use to do this:

    /// <summary>
    /// Send an Email
    /// </summary>
    /// <param name="host">Example: smtp.gmail.com</param>
    /// <param name="port">Port to send email</param>
    /// <param name="from">Example: Email@gmail.com</param>
    /// <param name="password">Password</param>
    /// <param name="toList">List of people to send to</param>
    /// <param name="subject">Subject of email</param>
    /// <param name="messsage">Meddage of emial</param>
    /// <param name="deliveryMethod">Deliever type</param>
    /// <param name="isHtml">Is email HTML</param>
    /// <param name="useSSL">Is email SSL</param>
    /// <param name="ccList">List of people to cc</param>
    /// <param name="atachmentList">List of attachment files</param>
    public void SendMessage(string host, int port, string from, string password, List<string> toList, string subject, string messsage,
        SmtpDeliveryMethod deliveryMethod, bool isHtml, bool useSSL, List<string> ccList, List<string> atachmentList)
    {
        try
        {
            SmtpClient smtpClient = new SmtpClient(host);
            smtpClient.DeliveryMethod = deliveryMethod;
            smtpClient.Port = port;
            smtpClient.EnableSsl = useSSL;
            if (!string.IsNullOrEmpty(password))
                smtpClient.Credentials = new NetworkCredential(from, password);

            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress(from);
            mailMessage.Subject = subject;
            mailMessage.IsBodyHtml = isHtml;
            mailMessage.Body = messsage;

            if (toList != null)
            {
                for (int i = 0; i < toList.Count; i++)
                {
                    if (!string.IsNullOrEmpty(toList[i]))
                        mailMessage.To.Add(toList[i]);
                }
            }

            if (ccList != null)
            {
                for (int i = 0; i < ccList.Count; i++)
                {
                    if (!string.IsNullOrEmpty(ccList[i]))
                        mailMessage.CC.Add(ccList[i]);
                }
            }

            if (atachmentList != null)
            {
                for (int i = 0; i < atachmentList.Count; i++)
                {
                    if (!string.IsNullOrEmpty(atachmentList[i]))
                        mailMessage.Attachments.Add(new Attachment(atachmentList[i]));
                }
            }

            try
            {
                smtpClient.Send(mailMessage);
            }

            catch
            {
            }
        }
        catch
        {
        }
    }

I just through a try-catch around everything and did minimal error checking. Hovere, this is the solution you are looking form I hope.

MyKuLLSKI
  • 5,285
  • 3
  • 20
  • 39
0

You can use the System.Net.Mail namespace.

The SmtpClient topic in MSDN has a good example of how to do this.

This will require you to embed an SMTP server name or address in your application and this email sending could easily be blocked by corporate or ISP policies (i.e. some ISPs only allow requests to their specific SMTP servers, in large part to block or control spam).

competent_tech
  • 44,465
  • 11
  • 90
  • 113
0

You can use a library like Chilkat or you can connect to a SMTP server using built in .Net stuff like this using system.net.mail.

If your client is running a anti-virus program this is going to be blocked, but there are ways around that if you google.

skub
  • 137
  • 1
  • 5
0

If you are sending your email through an Exchange 2010 server, then you have another option, in Exchange 2010, it provide a web service, which will provide you the full control of the mailbox.

You can download the SDK from Exchange server SDK

Johnny
  • 363
  • 1
  • 8
  • It is rarely desirable to implement the Exchange SDK directly. This provides a less than scalable solution and should only be considered if the scope of your application is limited to LAN only. – M.Babcock Jan 15 '12 at 08:07
  • The Exchange Server SDK , is based on Web Service, and certainly it is not limited to LAN only, please do some investigation before make comments, and confuse other people. certainly , what kind of solution people choose depends on the requirement. I just point out another way for them. – Johnny Jan 15 '12 at 09:48