What is the port and host? Becuase it throws an host not found exception
URL smtp.gmail.com
Port: 587
Using credentials and enabling Ssl
If I use port 465 the application doesn't throw an Excepcion but Gmail is not receiving.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hector Hugo Alpizar CesenaPosted May 10, 2010, 12:50 PM
Amit ChoudharyPosted May 8, 2010, 11:22 PM
try below code
usingSystem.Web.Mail;.usingSystem;publicclassMailSender{publicstaticboolSendEmail(stringpGmailEmail,stringpGmailPassword,stringpTo,stringpSubject,stringpBody,System.Web.Mail.MailFormat pFormat,stringpAttachmentPath){try{System.Web.Mail.MailMessage myMail =newSystem.Web.Mail.MailMessage();myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","smtp.gmail.com");myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport","465");myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing","2");//sendusing: cdoSendUsingPort, value 2, for sending the message using//the network.//smtpauthenticate: Specifies the mechanism used when authenticating//to an SMTP//service over the network. Possible values are://- cdoAnonymous, value 0. Do not authenticate.//- cdoBasic, value 1. Use basic clear-text authentication.//When using this option you have to provide the user name and password//through the sendusername and sendpassword fields.//- cdoNTLM, value 2. The current process security context is used to// authenticate with the service.myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");//Use 0 for anonymousmyMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",pGmailEmail);myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",pGmailPassword);myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl","true");myMail.From = pGmailEmail;myMail.To = pTo;myMail.Subject = pSubject;myMail.BodyFormat = pFormat;myMail.Body = pBody;if(pAttachmentPath.Trim() !=""){MailAttachment MyAttachment =newMailAttachment(pAttachmentPath);myMail.Attachments.Add(MyAttachment);myMail.Priority = System.Web.Mail.MailPriority.High;}System.Web.Mail.SmtpMail.SmtpServer ="smtp.gmail.com:465";System.Web.Mail.SmtpMail.Send(myMail);returntrue;}catch(Exception ex){throw;}}}
code Please mark as "Do you like this post" if it helps you