Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

joyhenrry
More...


Resources » Code Snippets » Email

Sending Emails from Google Server


Posted Date:     Category: Email    
Author: Member Level: Platinum    Points: 15



 


Some time we need to send mails to others from our application, and fro this we need to use some free email server like GMAIL. here is the code using that we can use the gmail mail server to send the mails. I am simply specifying the g mail SMTP server name and the Port number in the code.. take a look…



MailMessage mailMessage = new MailMessage();

mailMessage.To.Add(”test@test.com”);

mailMessage.Subject = “Test”;

mailMessage.Body = “This is a test mail”;

mailMessage.IsBodyHtml = true;

// Create the credentials to login to the gmail account associated with my custom domain

string sendEmailsFrom = “abc@xyz.com”;

string sendEmailsFromPassword = “password”;


NetworkCredential cred = new NetworkCredential(sendEmailsFrom, sendEmailsFromPassword);

SmtpClient mailClient = new SmtpClient(”smtp.gmail.com”, 587);

mailClient.EnableSsl = true;

mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

mailClient.UseDefaultCredentials = false;

mailClient.Timeout = 30000;

mailClient.Credentials = cred;

mailClient.Send(mailMessage);



Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA





Did you like this resource? Share it with your friends and show your love!


Responses to "Sending Emails from Google Server"
Author: R.Jaya kumar (JK)    01 Jul 2009Member Level: Gold   Points : 1
Dear Sir

pl change this code .vb

how to include imports web.net

pl change this error check jpg file here



Author: Anil Kumar Pandey    01 Jul 2009Member Level: Platinum   Points : 1
hi,

u can use the Code converter available in DNS. and for that error please import the System.Net.Mail; name space

like

Imports System.Net.Mail;

Thanks




Author: R.Jaya kumar (JK)    01 Jul 2009Member Level: Gold   Points : 1
Dear Sir

thanks ur reply and ur help very thankful
advantages of the code

following error comes

A from address must be specified.




Author: Anil Kumar Pandey    01 Jul 2009Member Level: Platinum   Points : 1
hi,
please specify the form address there..
like this


Message.From.Add(address);



Author: R.Jaya kumar (JK)    01 Jul 2009Member Level: Gold   Points : 2


Dim mailMessage As MailMessage = New MailMessage()

mailMessage.To.Add("test@test.com")

mailMessage.Subject = "Test"

mailMessage.Body = "This is a test mail"


mailMessage.IsBodyHtml = True

' Create the credentials to login to the gmail account associated with my custom domain

Dim sendEmailsFrom As String = "abc@xyz.com"

Dim sendEmailsFromPassword As String = "password"

Dim address1 As String = "Wesdsdfsdf"



Dim cred As Net.NetworkCredential = New Net.NetworkCredential(sendEmailsFrom, sendEmailsFromPassword)

Dim mailClient As SmtpClient = New SmtpClient("smtp.gmail.com", 587)

mailClient.EnableSsl = True

mailClient.DeliveryMethod = SmtpDeliveryMethod.Network

mailClient.UseDefaultCredentials = False

mailClient.Timeout = 30000

mailClient.Credentials = cred

Message.From.Add(address);

mailClient.Send(mailMessage)


message convert mailMessage ?
pl change this code



Author: Dadasaheb k. Chobhe    22 Jul 2009Member Level: Bronze   Points : 1
Greet Sir,
I was tried at my level. But it gives error remote name could not resolve : smtp.gmail.com.
pls give me reply.



Author: Abhay Kumar Raut    14 Aug 2009Member Level: Gold   Points : 1
Hi Anil,

good one .

keep it up.

contribute more.

Thanks and Regards
Abhay



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Send Email using smtpClient
    Previous Resource: Send Email
    Return to Resources
    Post New Resource
    Category: Email


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Gmial  .  Sending mail from gmails  .  Send mails  .  SMTP  .  Anil Kumar Pandey  .  Anil Pandey  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.