如何使用javascript发送电子邮件 [英] how to send Email using javascript

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

问题描述

如何使用javascript

how to send Email using javascript

推荐答案

如何发送电子邮件您不能直接使用Javascript发送电子邮件,因为它只是客户端,您需要服务器做到这一点.

当然,您可以使用"mailto:"作为解决方法.

一个小的Google搜索给了我很多结果,甚至在CP中也有一个问题: ^ ]

其他:
http://www.roseindia.net/answers/viewqa/PHP/14717-send-mail-using-JavaScript.html [ ^ ]

http://stackoverflow.com/questions/271171/sending-emails-with-javascript [ ^ ]

搜索Google是一个不错的起点...
You can''t send an e-mail directly with Javascript as it is only client side and you need the server side to do that.

Of course you can use "mailto:" as a workaround.

A small google search has given me lot''s of results, even one question in CP: How to send Mail using Javascript[^]

And others:
http://www.roseindia.net/answers/viewqa/PHP/14717-send-mail-using-JavaScript.html[^]

http://stackoverflow.com/questions/271171/sending-emails-with-javascript[^]

Searching Google is a good starting point...


如果您使用uisng Asp .net
发送邮件,则to mail不能发送邮件
然后
//使用此代码发送邮件,但如果与其他人一起使用则只能与gmail一起使用,然后更改此代码即可.nly端口号
objSMTPClient.Port = 587;


mail to does not work to send a mail if u r sending mail uisng Asp .net

then
// use this code to send mail but it only work with gmail if you r working with other then change this code nly port no
objSMTPClient.Port = 587;


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;

试试
{
电子邮件("dksingh6788@gmail.com","devendrak@fitatechnologies.com",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("dksingh6788@gmail.com", "devendrak@fitatechnologies.com", 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发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆