Sending Mail from asp.net for Gmail ID

  • Thread starter Thread starter jack
  • Start date Start date
J

jack

Hi,
Im trying to send mail from asp.net page to gmail account.
Im trying to do this with the help of below code, but cant archive
it.



MailMessage message = new MailMessage("(e-mail address removed)", "(e-mail address removed)",
"(e-mail address removed)", "(e-mail address removed)");
SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
smtp.Send(message);



The above code doesn't seem to work..

Please help
 
Im trying to send mail from asp.net page to gmail account.
Im trying to do this with the help of below code, but cant archive
it.
MailMessage message = new MailMessage("(e-mail address removed)", "(e-mail address removed)",
"(e-mail address removed)", "(e-mail address removed)");
SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
smtp.Send(message);

The above code doesn't seem to work..

There are several things here:

1) You don't need to use GMail as the relay server just because you want to
send email *to* a Gmail account...

2) What you mean by "can't archive it"? What archive are you talking
about...?

3) The MailMessage() object declaration is incorrect:
http://www.systemnetmail.com/faq/3.1.1.aspx
 
Here is sample working Gmail Sender code. Watch carefully at everything that
is done:

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

namespace PAB.Utils
{
public static class Sender
{
public static void SendGmail(string userName, string password,
string mailFrom,
string mailTo,string subject, string
message,bool isBodyHtml)
{
System.Net.Mail.MailMessage msg = new
System.Net.Mail.MailMessage(mailFrom,mailTo,
subject, message);
msg.IsBodyHtml = isBodyHtml;
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
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com
 
You should not send your message to gmail directly.

Instead, use the SMTP server that belongs to your domain/internet provider.
 
Peter Bromberg said:
Here is sample working Gmail Sender code. Watch carefully at everything that
is done:

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

namespace PAB.Utils
{
public static class Sender
{
public static void SendGmail(string userName, string password,
string mailFrom,
string mailTo,string subject, string
message,bool isBodyHtml)
{
System.Net.Mail.MailMessage msg = new
System.Net.Mail.MailMessage(mailFrom,mailTo,
subject, message);
msg.IsBodyHtml = isBodyHtml;
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
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com
 
I want a lot of thing but I do not post them all here :)

If you have a question then ask and do not forget to provide specific
problem you face with descriptive error you get (if any)

George.
 
Back
Top