如何使用smtp服务在gmail上发送电子邮件? [英] How to send email on gmail using smtp service?
本文介绍了如何使用smtp服务在gmail上发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我们必须使用smtp协议在按钮单击事件上向gmail发送电子邮件.下面给出的代码不起作用.请给我解决方案.
谢谢.
In my application,we have to send email to gmail on button click event using smtp protocol.The code given below doesn''t work.Please give me solution.
Thank You.
string emailid;
string Subject = "Request For Registration";
string MailBody = "Please Approve My Request";
string strquery3 = "select EmailId From tblAdmin_Registration Where(FacultyId = '" + facultyid + "')";
objsqlcommand = new SqlCommand(strquery3, objsqlconnection);
try
{
SqlDataAdapter adapter = new SqlDataAdapter(objsqlcommand);
DataTable table = new DataTable();
adapter.Fill(table);
if (table.Rows.Count > 0)
{
Server.ScriptTimeout = 1000;
Response.Flush();
emailid = table.Rows[0]["EmailId"].ToString();
MailMessage ObjMail = new MailMessage();
SmtpClient ObjSmtpServer = new SmtpClient("objSmtpServer.gmail.com");
ObjMail.From = new MailAddress(txtemail.Text);
ObjMail.To.Add(emailid);
ObjMail.Subject = Subject;
ObjMail.Body = MailBody;
try
{
ObjSmtpServer.Send(ObjMail);
}
catch
{
Response.Write("Error in sending Mail");
}
Response.Flush();
}
}
catch
{
Response.Write("Error111111111111........");
}
推荐答案
^ ]
http://www. shabdar.org/asp-net/111-send-email-from-your-gmail-account-using-aspnet-and-c.html [
Sending mail using Asp.net[^]
http://www.shabdar.org/asp-net/111-send-email-from-your-gmail-account-using-aspnet-and-c.html[^]
may help
尝试使用此方法
try to use this method
public Boolean SendingMail(string From, string To, string Subject,string Body)
{
try
{
MailMessage m = new MailMessage("Uma Shankar<test1@gmail.com>", To);
m.Subject = Subject;
m.Body = Body;
m.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.google.com";
NetworkCredential authinfo = new NetworkCredential("test@gmail.com", "123456.com");
smtp.UseDefaultCredentials = false;
smtp.Credentials = authinfo;
smtp.Send(m);
return true;
}
catch (Exception ex)
{
return false;
}
}
嗨
试试这个
使用默认的SMTP从C#应用程序发送电子邮件 [
Hi
try this one
Sending Emails from C# Application using default SMTP[^]
Thank you.
这篇关于如何使用smtp服务在gmail上发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文