Sending Mail from asp.net for Gmail ID

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
 
M

Mark Rae [MVP]

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
 
P

Peter Bromberg [C# MVP]

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
 
H

Henk Kelder

You should not send your message to gmail directly.

Instead, use the SMTP server that belongs to your domain/internet provider.
 
S

shobaguna

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
 
G

George Ter-Saakov

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.
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top