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

how to maintained the session from one page to another page based on the url and then entered into the first page is logging into instead of secondpage it goes to the another url.ie first login session togoes to the one url and next login session it goes to another url how is it possible in php please give me answer in that question

1 Answers   iCynergy,


What is use of echo in php?

0 Answers  


List some sorting functions in php?

0 Answers  


Is not null mysql?

0 Answers  


How to reset/destroy a cookie in php?

0 Answers  






Can php run on windows server?

0 Answers  


What is the tags in PHP is not a valid way to begin and end a PHP code block?

0 Answers  


What is full form of PHP?

0 Answers  


What is printf in php?

0 Answers  


What is the use of mysql_real_escape_string() function?

0 Answers  


When viewing an html page in a browser, the browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?

0 Answers  


What are php errors?

0 Answers  


Categories