C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Email »

Sending Emails from Google Server


Posted Date: 30 Jun 2009    Resource Type: Code Snippets    Category: Email
Author: Anil Kumar PandeyMember Level: Diamond    
Rating: 1 out of 5Points: 15 (Rs 5)



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



Responses

Author: R.Jaya kumar (JK)    01 Jul 2009Member Level: Diamond   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: Diamond   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: Diamond   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: Diamond   Points : 1
hi,
please specify the form address there..
like this


Message.From.Add(address);



Author: R.Jaya kumar (JK)    01 Jul 2009Member Level: Diamond   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    14 Aug 2009Member Level: Diamond   Points : 1
Hi Anil,

good one .

keep it up.

contribute more.

Thanks and Regards
Abhay


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
SMTP  .  Sending mail from gmails  .  Send mails  .  Gmial  .  Anil Pandey  .  Anil Kumar Pandey  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Send Email using smtpClient
Previous Resource: Send Email
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use