本文介绍了如何使用javascript发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript

how to send Email using javascript

推荐答案


using System.Net.Mail;
using System.Text;





受保护的void Submit_Click(对象发送者,EventArgs e)
{
如果(Txt1.Text ==")
{
Label6.Visible = true;
Label6.Text =输入公司名称";
}
否则,如果(TextBox2.Text ==")
{
Label6.Visible = true;
Label6.Text =输入全名";
}
否则,如果(TextBox3.Text ==")
{
Label6.Visible = true;
Label6.Text =输入电子邮件";
}
否则,如果(TextBox4.Text ==")
{
Label6.Visible = true;
Label6.Text =输入联系人号码";
}
否则,如果(TextBox5.Text ==")
{
Label6.Visible = true;
Label6.Text =输入dESCRIPTION";
}
其他
{
字符串str;
str =全名:" + Txt1.Text.ToUpper();
str = str +"Company:" + TextBox2.Text;
str = str +"Email:" + TextBox3.Text;
str = str +联系电话:" + TextBox4.Text;
str = str +描述:" + TextBox5.Text;

试试
{
电子邮件("[email protected]","[email protected]",str);
Response.Redirect("Thanku.aspx");

}
赶上{}
}

}
公共布尔电子邮件(字符串strFrom,字符串strTo,字符串strMessage)
{

试试
{
if(strFrom.Trim()!="&& strTo.Trim()!="&& strFrom.Trim()!= null&& strTo.Trim()!= null)
{
System.Net.Mail.MailMessage objMailMessage =新的System.Net.Mail.MailMessage();
objMailMessage.Body = strMessage;
objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
objMailMessage.IsBodyHtml = false;
objMailMessage.From =新的MailAddress(strFrom,一个鬼",System.Text.Encoding.UTF8);
objMailMessage.To.Add(新MailAddress(strTo));
//objMailMessage.CC.Add(new MailAddress(strTo));
objMailMessage.Subject =注册请求";
objMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
objMailMessage.Priority = MailPriority.High;
//如果(FileUpload1.HasFile)
//{
//objMailMessage.Attachments.Add(新附件(FileUpload1.PostedFile.InputStream,FileUpload1.FileName));
//}

试试
{

System.Net.Mail.SmtpClient objSMTPClient =新的System.Net.Mail.SmtpClient();
objSMTPClient.Credentials =新的System.Net.NetworkCredential(strFrom,您的Gmail密码");//请输入Gmail密码
//objSMTPClient.Credentials = objSMTPClient.Credentials.GetCredential(objSMTPClient.Host,objSMTPClient.Port,"Digest");
objSMTPClient.Port = 587;
objSMTPClient.Host ="smtp.gmail.com";
objSMTPClient.EnableSsl = true;
//objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSMTPClient.Send(objMailMessage);

}
catch(ex ex例外)
{
返回false;
}
}
}

catch(ex ex例外)
{
返回false;
}
返回true;

}





protected void Submit_Click(object sender, EventArgs e)
{
if (Txt1.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The company name";
}
else if (TextBox2.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The Full name";
}
else if (TextBox3.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The EMail";
}
else if (TextBox4.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The Contact no";
}
else if (TextBox5.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The dESCRIPTION";
}
else
{
String str;
str = "Full Name :" + Txt1.Text.ToUpper();
str = str + "Company : " + TextBox2.Text;
str = str + "Email : " + TextBox3.Text;
str = str + "Contact no : " + TextBox4.Text;
str = str + "Description : " + TextBox5.Text;

try
{
Email("[email protected]", "[email protected]", str);
Response.Redirect("Thanku.aspx");

}
catch { }
}

}
public bool Email(string strFrom, string strTo, string strMessage)
{

try
{
if (strFrom.Trim() != "" && strTo.Trim() != "" && strFrom.Trim() != null && strTo.Trim() != null)
{
System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage();
objMailMessage.Body = strMessage;
objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
objMailMessage.IsBodyHtml = false;
objMailMessage.From = new MailAddress(strFrom, "One Ghost", System.Text.Encoding.UTF8);
objMailMessage.To.Add(new MailAddress(strTo));
//objMailMessage.CC.Add(new MailAddress(strTo));
objMailMessage.Subject = "Registration Request";
objMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
objMailMessage.Priority = MailPriority.High;
//if (FileUpload1.HasFile)
//{
// objMailMessage.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
//}

try
{

System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient();
objSMTPClient.Credentials = new System.Net.NetworkCredential(strFrom, "you gmail password");// please insert gmail password
//objSMTPClient.Credentials = objSMTPClient.Credentials.GetCredential(objSMTPClient.Host, objSMTPClient.Port, "Digest");
objSMTPClient.Port = 587;
objSMTPClient.Host = "smtp.gmail.com";
objSMTPClient.EnableSsl = true;
//objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSMTPClient.Send(objMailMessage);

}
catch (Exception ex)
{
return false;
}
}
}

catch (Exception ex)
{
return false;
}
return true;

}


这篇关于如何使用javascript发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:54