Jan 30, 2011

How To: Send Mail Using Google Mail Apps (ASP.Net)



As a freelancer web developer usually I work with clients who prefer to let me handle his hosting too, so the idea of bringing them to a host that I own and make a profit out of it appeared in my mind.
The main problem I faced was always mail related limitations as:

  • Stupid web mail interfaces
  • Arabic encoding problems in the web mail interfaces
  • Mailbox spaces related problems –As it’s eating from my current hosting space-
  • Limited attachment size
  • Google Apps was the ultimate solution for all these problems, simply you have to create an account for your domain HERE and the wizard will take you through the whole process and finally you’ll be providing your clients the best mail services ever branded by their domain.
Usually I change the SMTP to point to the new mail server and everything works fine, this time the result was nothing :| , so I wear the gloves and started a new R&D mission.
After a medium investigation included testing a some available solutions I’ve found the 2 below easy steps to make it work:
1. Add the following code under tag </configSections>:
    <system.net>
    <mailSettings>
    <smtp from=”mail@mail.com” deliveryMethod=”Network”>
    <network host=”smtp.gmail.com” port=”587″ userName=”mail@mail.com ” password=”password”/>
    </smtp>
    </mailSettings>
    </system.net>
    Notes:
    • Replace “mail@mail.com” with an exist Google mail account
    • Replace “password” with this mail password
    2. Use the below sending code (VB.Net):
    Dim email As New Net.Mail.MailMessage
    email.To.Add(“to@mail.com”)
    email.From = New Net.Mail.MailAddress(“from@mail.com”)
    email.Body = “Message body”
    email.Subject = “Message subject”
    email.IsBodyHtml = True
    Dim client As New Net.Mail.SmtpClient()
    client.EnableSsl = True
    client.Send(email)

    Notes:
    • Replace to@mail.com with the receiver mail
    • Replace from@mail.com with the sender mail
    • Replace “Message body” and “Message subject” with your appropriate text
    3. Enjoy!!
    via [http://www.ellaboudy.com]


    For Further Reading,
    google, How to

    0 comments:

    Post a Comment

     

    Popular Posts

    Popular Posts On EAB

    Man Behind This Blog