How can we send mail using JavaScript?

Answers were Sorted based on User's Feedback



How can we send mail using JavaScript?..

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

How can we send mail using JavaScript?..

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

How can we send mail using JavaScript?..

Answer / ramesh

hi
how can send mail using java script
i want examples code

Is This Answer Correct ?    37 Yes 22 No

How can we send mail using JavaScript?..

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

How can we send mail using JavaScript?..

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

How can we send mail using JavaScript?..

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

How can we send mail using JavaScript?..

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

How can we send mail using JavaScript?..

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

How can we send mail using JavaScript?..

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

How can we send mail using JavaScript?..

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

Post New Answer

More PHP Interview Questions

What is slim framework?

0 Answers  


Is nan in javascript?

0 Answers  


Write a program to get lcm of two numbers using php?

0 Answers  


hi! i am tushar. i am trying to insert digital signature in a pdf file using PHP. i create a digital signature jpg image using imagecreatefromjpeg() function, but whenever i trying to insert it into my pdf file it shown this error. "FPDF error: Not a JPEG file: signature.jpg". could some one help me? how can i insert a digital signature in a pdf file using PHP?

1 Answers  


What is the use of print_r function in php?

0 Answers  






What is the ioncube php loader?

0 Answers  


How does the identity operator === compare two values?

0 Answers  


Tell me is it possible to remove the html tags from data?

0 Answers  


hai, friend i srinu i had completed my graduation in 2004. now i am fineshed PHP course .may i get any oppartunity on php progr pls sugg me . thank u

0 Answers  


hai plz inform me specific books fo0r paper1,paper2 and paper 3 of group2 examination... plz giv me at the earliest......

1 Answers   APPSC, HCL,


what are the various PHP Script Optimization techniques?

1 Answers   IBM, Krify Software Technologies, TCL,


How can we know that a session is started or not?

8 Answers  


Categories