send mail with gmail

F

fredd00

Hi

i'm trying to send email through my gmail account, used to work

web.config

<system.net>
<mailSettings>
<smtp from="myfrom" >
<network defaultCredentials="true" host="smtp.gmail.com"
port="465" userName="mygmailusername" password="mygmailpassword"/>
</smtp>
</mailSettings>
</system.net>

my fonction

public static void SendEmail(string To, string From, string Subject,
string Body, bool IsBodyHtml)
{
try
{
using (MailMessage message = new MailMessage(From, To,
Subject, Body))
{
message.IsBodyHtml = IsBodyHtml;
SmtpClient mailClient = new SmtpClient();
mailClient.Send(message);
}
}
catch (SmtpException ex)
{
throw new ApplicationException("SmtpException has
Occured: " + ex.Message);
}
}

i get either error :
1-
SmtpException has Occured: The SMTP server requires a secure
connection or the client was not authenticated. The server response
was: 5.7.0 Must issue a STARTTLS command first e13sm6192679qba.37

or
2 - when i enable ssl
SmtpException has Occured: The SMTP server requires a secure
connection or the client was not authenticated. The server response
was: 5.5.1 Authentication Required e11sm6169311qbc.5


who can it be solved ?
also who can i use this account to send email through the password
recovery control ?
thanks
 
P

Peter Bromberg [C# MVP]

Try doing it with a chunky method:


using System;
using System.Collections.Generic;
using System.Text;

namespace PAB.SEO
{
public static class GmailSender
{
public static void SendGmail(string userName, string password,
string mailFrom,
string mailTo, string commaDelimCCs, string
subject, string message, bool isBodyHtml)
{
System.Net.Mail.MailMessage msg = new
System.Net.Mail.MailMessage(mailFrom, mailTo,
subject, message);
msg.IsBodyHtml = isBodyHtml;
if(commaDelimCCs!="")
msg.CC.Add(commaDelimCCs );
System.Net.NetworkCredential cred = new
System.Net.NetworkCredential(userName, password);
System.Net.Mail.SmtpClient mailClient = new
System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = cred;
mailClient.Send(msg);
}
}
}

--Peter
Site: http://www.eggheadcafe.com
UnBlog: htp://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
 
F

fredd00

i'm still getting the error
The SMTP server requires a secure connection or the client was not
authenticated. The server response was: 5.7.0 Must issue a STARTTLS
command first f18sm8426670qba.14

but the emails seems to be sent anyway, i'm receiving my message
 
F

fredd00

it actually works fine
the error is poped because i'm using the password recovery control,
which doesn't seem to like my network config
i simply cancel the event after sending the email through my email
method

thanks
 
G

good_zeus

Hi

i'm trying to send email through my gmail account, used to work

web.config

<system.net>
<mailSettings>
<smtp from="myfrom" >
<network defaultCredentials="true" host="smtp.gmail.com"
port="465" userName="mygmailusername" password="mygmailpassword"/>
</smtp>
</mailSettings>
</system.net>

my fonction

public static void SendEmail(string To, string From, string Subject,
string Body, bool IsBodyHtml)
{
try
{
using (MailMessage message = new MailMessage(From, To,
Subject, Body))
{
message.IsBodyHtml = IsBodyHtml;
SmtpClient mailClient = new SmtpClient();
mailClient.Send(message);
}
}
catch (SmtpException ex)
{
throw new ApplicationException("SmtpException has
Occured: " + ex.Message);
}
}

i get either error :
1-
SmtpException has Occured: The SMTP server requires a secure
connection or the client was not authenticated. The server response
was: 5.7.0 Must issue a STARTTLS command first e13sm6192679qba.37

or
2 - when i enable ssl
SmtpException has Occured: The SMTP server requires a secure
connection or the client was not authenticated. The server response
was: 5.5.1 Authentication Required e11sm6169311qbc.5


who can it be solved ?
also who can i use this account to send email through the password
recovery control ?
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top