How can we send mail using JavaScript?
Answers were Sorted based on User's Feedback
Answer / naaz
There is no way of sending an email with javascript alone.
Your only possible option is to use a server-side script
(PHP, Perl, ASP) to email the form results to you.
To be more specific, your <FORM> line would look something
like this:
<form method=yest action=myscript.cgi>
The file "myscript.cgi" is a Perl or PHP program you wrote
and uploaded to the server. That program displays the
results to the user and then emails you the results.
It's just a misleading point to say u can still send an
email thru javascript (mailto:) plz understand that it
only opens a client side email program but doesnt send an y
email you wud definitely need a server side language to
send an email
cheerss
Is This Answer Correct ? | 99 Yes | 30 No |
Answer / lakum
function myfunction(form)
{
tdata=document.myform.tbox1.value;
location=?mailto:dep7abc@leeds.ac.uk?
subject=?+tdata+?/MYFORM?;
return true;
}
Is This Answer Correct ? | 96 Yes | 65 No |
Answer / ramesh
hi
how can send mail using java script
i want examples code
Is This Answer Correct ? | 37 Yes | 22 No |
Answer / muralidhar k
public void sendMail(String from, String to, String
subject, String messageBody, String[] attachments) throws
Exception
{
Properties props = System.getProperties();
props.put(SMTPHost, SMTPServer);
Session session = Session.getDefaultInstance
(props, null);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient
(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
BodyPart messageBodyPart = new MimeBodyPart
();
messageBodyPart.setText(messageBody);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
addAtachments(attachments, multipart);
message.setContent(multipart);
Transport.send(message);
}
protected void addAtachments(String[] attachments,
Multipart multipart) throws Exception
{
for(int i = 0; i<= attachments.length-1;
i++)
{
String filename = attachments[i];
MimeBodyPart attachmentBodyPart =
new MimeBodyPart();
DataSource source = new
FileDataSource(filename);
attachmentBodyPart.setDataHandler
(new DataHandler(source));
if (i==0)
{
attachmentBodyPart.setFileName("ResultLog.txt");
}
if (i==1)
{
attachmentBodyPart.setFileName("ErrorLog.txt");
}
multipart.addBodyPart
(attachmentBodyPart);
}
}
public static void Mail() throws Exception
{
try
{
String bv = BuildVersion;
DriverScript client = new
DriverScript();
String from
= "murali@gmail.com";
String subject = "REG : " +
ProjectName + " Regression Suite Execution for Build " +
bv ;
String message
= "Hello,\n\n" +
"Regression Suite Execution for " +
ProjectName + " has been completed for the build " +
BuildVersion + ".\n\n" +
"Please find the attached
Result Logs and Error Logs\n\n" +
"Thanks.\n\n" +
"Regards,\n" +
"ZVS - Automation Testing
Team || Zylog Systems Ltd\n" +
"---------------------------
-------------------------------------------------------" +
"\n" +
"Please do not reply to
this Email!! It is only an Automated Notification";
String ResultLog = TestLog
+ "ExecutionLog_" + DriverScript.GetDate() + ".txt";
String ErrorLog = TestLog
+ "ErrorLog_" + DriverScript.GetDate() + ".txt";
String[] filenames1 =
{ResultLog, ErrorLog};
String Rec =
No_Of_Recipients;
int Recipients =
Integer.parseInt(Rec);
if
(SendMail.equalsIgnoreCase("Y"))
{
for (int i=1;
i<=Recipients; i++)
{
String To
= "Recipient" + i;
String To1 =
DriverScript.Config(To);
client.sendMail
(from, To1, subject, message, filenames1);
}
}
}
catch(Exception e)
{
DriverScript.ErrorInfo
(e.getMessage());
e.printStackTrace();
}
}
Is This Answer Correct ? | 17 Yes | 9 No |
Answer / $lv@ganapathy.k
You can send via Using asp.net.
Use the following Assembly System.Web.Mail;
// Instantiate a new instance of MailMessage
MailMessage mMailMessage = new MailMessage();
// Set the sender address of the mail message
mMailMessage.From = new MailAddress(from);
// Set the recepient address of the mail message
mMailMessage.To.Add(new MailAddress(to));
// Check if the bcc value is null or an empty string
if ((bcc != null) && (bcc != string.Empty))
{
// Set the Bcc address of the mail message
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
// Check if the cc value is null or an empty value
if ((cc != null) && (cc != string.Empty))
{
// Set the CC address of the mail message
mMailMessage.CC.Add(new MailAddress(cc));
} // Set the subject of the mail message
mMailMessage.Subject = subject;
// Set the body of the mail message
mMailMessage.Body = body;
// Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal;
// Instantiate a new instance of SmtpClient
SmtpClient mSmtpClient = new SmtpClient();
// Send the mail message
mSmtpClient.Send(mMailMessage);
Try to read Proxy address,username and password from
web.config file.
Is This Answer Correct ? | 17 Yes | 14 No |
Answer / santhoshsiva
Ok Ok? i want a new & simple method for send a form to Email
with the help of JSP
Is This Answer Correct ? | 13 Yes | 12 No |
Answer / mark
Muralidhar K can you plz tell how to call your code. Do i
have to call it like:
<body onload="Mail()">
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / ramesh
At jsscript tag
function sendmail(_frm)
{
var eml="you@youraddress.com";
var bod="&body="+_frm.selOne.value+" ¦¦ "+_frm.txtOne.value;
var subj="?subject=Whatever you want";
location.href="mailto:"+eml+subj+bod;
}
At Form tag
<form action="mailto:you@youraddress.com"
enctype="text/plain"
method="POST" onsubmit="sendmail(this);return false;">
Is This Answer Correct ? | 28 Yes | 30 No |
Answer / sajeer
<?
extract($_GET);
extract($_POST);
$txtname=stripslashes($T1);
$msg="CONTACT US INFORMATION\n\n";
$msg.="Subject : $T4\n";
$msg.="From : $T1\n";
$msg.="Email : $T2\n";
if($T3!="")
$msg.="Phone : $T3\n\n";
$txt=stripslashes($S1);
if($S1!="")
$msg.="Comments : $txt";
@mail("sajeerm@yahoo.com","Contact Query from
$T1 ","$msg","From:admin@sajeer.com");
?>
Is This Answer Correct ? | 3 Yes | 6 No |
Answer / viswambharan
<script type="text/javascript" language="javascript">
<form action = "mailto:http://www.gmail.com" enctype="text/plain" method="post">
First Name:<input type="text" name="Firstname" id="name">
Email Address:<input type="text" name="Email Address" id="email">
<input type="submit" name="Sent Mail" id="Send">
Is This Answer Correct ? | 1 Yes | 5 No |
How to terminate the execution of a script in PHP?
How to set a value in session? How to remove data from a session?
What is difference between $x and $$x
5 Answers Mindex, Net Solution, Procon IT Solutions, Trigent,
Is PHP is procedure oriented or object oriented?
How to implement a class named dragonball. This class must have an attribute named ballcount (which starts from 0) and a method ifoundaball. When ifoundaball is called, ballcount is increased by one. If the value of ballcount is equal to seven, then the message you can ask your wish is printed, and ballcount is reset to 0. How would you implement this class?
Tell me what does accessing a class via :: means?
What is Type hinting in PHP?
What are magic methods in php
What are the advantages of using php?
What is php variable?
What is the use of rand() in php?
What is call by reference in php?