本地托管和Windows托管SMTP电子邮件..... [英] Local hosting and windows hosting SMTP email.....
本文介绍了本地托管和Windows托管SMTP电子邮件.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Web.config文件包含该代码
Web.config file contains that code
<appSettings>
<add key="FromMail" value="info@domain.ae"/>
<add key ="Password" value="password"/>
<add key ="Host" value="smtp.gmail.com"/>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
,其余代码在这里
and the remaining code is here
protected void BtnSubmit_Click(object sender, EventArgs e)
{
try
{
if (email1.Text.Contains("@") || email1.Text.Contains(".com"))
{
toEmail = email1.Text;
EmailSubj = Convert.ToString("Worktops.ae");
EmailMsg = Convert.ToString("Hello!");
CompanyMsg = Convert.ToString("Team WORKTOPS.ae<br> Customer: " + name1.Text + "");
//passing parameter to Email Method
SendEmail.Email_Without_Attachment(toEmail, EmailSubj, EmailMsg);
SendEmail.Email_Without_Attachment1("info@domain.ae", EmailSubj, CompanyMsg);
string message = "Thank you for contacting us. We will get back you soon...";
Page.ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}
else
{
string message = "Please Put an Valid Email address";
Page.ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}
}
catch (Exception x)
{
}
}
/ ************************************************** *****************************/
/***************************************************************************/
public static class SendEmail
{
public static string Pass, FromEmailid, HostAdd;
public static void Email_Without_Attachment(String ToEmail, String Subj, string Message)
{
//Reading sender Email credential from web.config file
HostAdd = ConfigurationManager.AppSettings["Host"].ToString();
FromEmailid = ConfigurationManager.AppSettings["FromMail"].ToString();
Pass = ConfigurationManager.AppSettings["Password"].ToString();
//creating the object of MailMessage
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(FromEmailid); //From Email Id
mailMessage.Subject = Subj; //Subject of Email
mailMessage.Body = Message; //body or message of Email
mailMessage.IsBodyHtml = true;
mailMessage.To.Add(new MailAddress(ToEmail)); //reciver's Email Id
SmtpClient smtp = new SmtpClient(); // creating object of smptpclient
smtp.Host = HostAdd; //host of emailaddress for example smtp.gmail.com etc
//network and security related credentials
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = mailMessage.From.Address;
NetworkCred.Password = Pass;
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mailMessage); //sending Email
}
public static void Email_Without_Attachment1(String ToEmail, String Subj, string Message)
{
//Reading sender Email credential from web.config file
HostAdd = ConfigurationManager.AppSettings["Host"].ToString();
FromEmailid = ConfigurationManager.AppSettings["FromMail"].ToString();
Pass = ConfigurationManager.AppSettings["Password"].ToString();
//creating the object of MailMessage
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(FromEmailid); //From Email Id
mailMessage.Subject = Subj; //Subject of Email
mailMessage.Body = Message; //body or message of Email
mailMessage.IsBodyHtml = true;
mailMessage.To.Add(new MailAddress(ToEmail)); //reciver's Email Id
SmtpClient smtp = new SmtpClient(); // creating object of smptpclient
smtp.Host = HostAdd; //host of emailaddress for example smtp.gmail.com etc
//network and security related credentials
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = mailMessage.From.Address;
NetworkCred.Password = Pass;
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mailMessage); //sending Email
}
}
我的尝试:
What I have tried:
Asalam u alaikum...
i am trying to send email using form in C# email is working properly on local host but not working when host properly. if anyone have idea so please help me
thanks
推荐答案
我将阅读此代码项目文章从Yahoo!发送电子邮件,GMail,Hotmail(C#) [ ^ ]
I would have a read of this code project article Send Email from Yahoo!, GMail, Hotmail (C#)[^]
这篇关于本地托管和Windows托管SMTP电子邮件.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文