I cannot send two emails with mailki - mailkit

I have a contact form on my web site, I want to send the client one email, and the second email goes to me I am baffled, all I can do is one, and tired everything, maybe you can help.
Here is my code thanks guys...:),
var message = new MimeMessage();
message.From.Add(new MailboxAddress(name, EM));
message.To.Add(new MailboxAddress("DBT WEB", "tony#dbtweb.com"));
message.Subject = string.Concat("DBTweb from ", " ", name);
var builder = new BodyBuilder();
var replaceLine = MSG.Replace(Environment.NewLine, "<br />");
var Theyear = DateTime.Now.Year;
builder.HtmlBody = string.Concat("Hi Tony this person sent you a message, the
persons name is <br /><br />", name, "<br /><br />The phone if any is
<strong>", PHnum, "</strong><br /><br />The city is <strong>", CIT, "</strong>
<br /><br />The State is <strong>", prov, "</strong><br /><br />The message is:
<br /><br />", replaceLine, "<br /><br />");
message.Body = builder.ToMessageBody();
var message1 = new MimeMessage();
message1.From.Add(new MailboxAddress("DBT WEB", "tony#dbtweb.com"));
message1.To.Add(new MailboxAddress(name, EM));
message1.Subject = string.Concat("Thank you from DBT WEB ", " ", name);
var builder1 = new BodyBuilder();
builder1.TextBody = string.Concat(#"Thank you for starting the discusstion on
your new web site possabilities ", name,
" I will get back to you in a few days, in the mean time I have attatached
my reume for your review, all the best," + " Tony Trapp ");
builder1.Attachments.Add(#"C:\ttrappresume5.docx");
message1.Body = builder1.ToMessageBody();
using (var emailClient = new MailKit.Net.Smtp.SmtpClient())
{
// email to me
emailClient.CheckCertificateRevocation = false;
emailClient.ServerCertificateValidationCallback = (s, c, h, e) => true;
emailClient.Connect("0.0.0.0", 25, false);
emailClient.Authenticate("tony#dbtweb.com", "T8sk?3o5"); // T8sk?3o5
emailClient.Send(message);
//emailClient.Send(message1);
emailClient.Disconnect(true);
return new JsonResult(name);

Related

Bold text on google form response email

I've this script done in google forms to send an email.
I'd like to add bold on "var message" and "message"
function onFormSubmit(e) {
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "Hello, this a new vacation request by an agent "+e.namedValues[headers[7]]+": \n \n";
var subject = "New Holiday Request";
for(i=1 ; i < 7; i++) {
message += headers[i] + ': ' + e.namedValues[headers[i]] + "\n\n";
}
var email = e.namedValues[headers[7]] + '#google.com';
//Logger.log(email);
MailApp.sendEmail(email, subject, message);
}
the result is:
Hello, this a new vacation request by an agent tayzer:
Timestamp: 5/15/2020 17:56:11
Start date (From the, included): 5/15/2020
the expected is:
Hello, this a new vacation request by an agent tayzer:
Timestamp: 5/15/2020 17:56:11
Start date (From the, included): 5/15/2020
How about this modification?
In this modification, the message including the bold type is sent using htmlBody. When your script is modified, please modify as follows.
From:
var message = "Hello, this a new vacation request by an agent "+e.namedValues[headers[7]]+": \n \n";
var subject = "New Holiday Request";
for(i=1 ; i < 7; i++) {
message += headers[i] + ': ' + e.namedValues[headers[i]] + "\n\n";
}
var email = e.namedValues[headers[7]] + '#google.com';
//Logger.log(email);
MailApp.sendEmail(email, subject, message);
To:
var html = "<b>Hello, this a new vacation request by an agent "+e.namedValues[headers[7]]+":</b><br><br>";
var subject = "New Holiday Request";
for(i=1 ; i < 7; i++) {
html += "<b>" + headers[i] + ':</b> ' + e.namedValues[headers[i]] + "<br><br>";
}
var email = e.namedValues[headers[7]] + '#google.com';
MailApp.sendEmail({to: email, subject: subject, htmlBody: html});
Note:
In this case, when the client can read the HTML mail, the bold type can be seen. When the client cannot read the HTML mail, the text is shown.
Reference:
sendEmail(message)

Ignoring blank email address input field Google Apps Script

I have an HTML form which contains email addresses from various suppliers. I am creating a kind of mail merge function so I can send all the contacts a personalised email when the form is submitted. Here is my .gs file:
function sendEmail(form) {
const sSheet = SpreadsheetApp.getActiveSpreadsheet();
const file = DriveApp.getFileById(sSheet.getId());
const documentUrl = file.getUrl();
/* var toEmail = form.toAddress;
var ccEmail = form.ccAddress;
var fromEmail = "****#*****.com";
var subject = form.subject;
var message = form.message; */
var toEmail = "";
var fromEmail = "****#*****.com";
var message = "";
var hotelAddresses = [
form.toAddress1,
form.toAddress2,
form.toAddress3,
form.toAddress4,
form.toAddress5,
form.toAddress6,
form.toAddress7,
form.toAddress8,
form.toAddress9,
form.toAddress10,
form.toAddress11,
form.toAddress12,
form.toAddress13,
form.toAddress14,
form.toAddress15,
form.toAddress16,
form.toAddress17,
form.toAddress18,
form.toAddress19,
form.toAddress20,
form.toAddress21,
form.toAddress22,
form.toAddress23,
form.toAddress24,
form.toAddress25,
form.toAddress26,
form.toAddress27,
form.toAddress28,
form.toAddress29,
form.toAddress30,
form.toAddress31,
form.toAddress32,
form.toAddress33,
];
var contactNames = [
form.contactName1,
form.contactName2,
form.contactName3,
form.contactName4,
form.contactName5,
form.contactName6,
form.contactName7,
form.contactName8,
form.contactName9,
form.contactName10,
form.contactName11,
form.contactName12,
form.contactName13,
form.contactName14,
form.contactName15,
form.contactName16,
form.contactName17,
form.contactName18,
form.contactName19,
form.contactName20,
form.contactName21,
form.contactName22,
form.contactName23,
form.contactName24,
form.contactName25,
form.contactName26,
form.contactName27,
form.contactName28,
form.contactName29,
form.contactName30,
form.contactName31,
form.contactName32,
form.contactName33,
];
var days = [
form.day1,
form.day2,
form.day3,
form.day4,
form.day5,
form.day6,
form.day7,
form.day8,
form.day9,
form.day10,
form.day11,
form.day12,
form.day13,
form.day14,
form.day15,
form.day16,
form.day17,
form.day18,
form.day19,
form.day20,
form.day21,
form.day22,
form.day23,
form.day24,
form.day25,
form.day26,
form.day27,
form.day28,
form.day29,
form.day30,
form.day31,
form.day32,
form.day33,
];
var dates = [
form.date1,
form.date2,
form.date3,
form.date4,
form.date5,
form.date6,
form.date7,
form.date8,
form.date9,
form.date10,
form.date11,
form.date12,
form.date13,
form.date14,
form.date15,
form.date16,
form.date17,
form.date18,
form.date19,
form.date20,
form.date21,
form.date22,
form.date23,
form.date24,
form.date25,
form.date26,
form.date27,
form.date28,
form.date29,
form.date30,
form.date31,
form.date32,
form.date33,
];
var times = [
form.time1,
form.time2,
form.time3,
form.time4,
form.time5,
form.time6,
form.time7,
form.time8,
form.time9,
form.time10,
form.time11,
form.time12,
form.time13,
form.time14,
form.time15,
form.time16,
form.time17,
form.time18,
form.time19,
form.time20,
form.time21,
form.time22,
form.time23,
form.time24,
form.time25,
form.time26,
form.time27,
form.time28,
form.time29,
form.time30,
form.time31,
form.time32,
form.time33,
];
var additionalInfo = [
form.additional1,
form.additional2,
form.additional3,
form.additional4,
form.additional5,
form.additional6,
form.additional7,
form.additional8,
form.additional9,
form.additional10,
form.additional11,
form.additional12,
form.additional3,
form.additional14,
form.additional15,
form.additional16,
form.additional17,
form.additional18,
form.additional19,
form.additional20,
form.additional21,
form.additional22,
form.additional23,
form.additional24,
form.additional25,
form.additional26,
form.additional27,
form.additional28,
form.additional29,
form.additional30,
form.additional31,
form.additional32,
form.additional33,
];
for(var i = 0; i<times.length; i++){
var subject = "Meeting - " + days[i] + ", " + dates[i] + " at " + times[i];
toEmail = hotelAddresses[i];
message = "Dear " + contactNames[i] + ","
+"<br><br>"+
"Please confirm the meeting on " + days[i] + " " + dates[i] + " at " + times[i] + "." + "<br>" + "<br>" +
additionalInfo[i] +
" If you could kindly let me know if you are able to confirm that would be great." + "<br>" + "<br>" +
"Many thanks and I look forward to hearing from you soon." + "<br>" + "<br>" +
"Yours sincerely," + "<br>" + "<br>" +
form.yourName + "<br>" + "<br>"
+ "<em><b>" + form.yourPosition + "</b></em> <br><br>" +
"<span style='color:#0e216d'><b> Company name. </b>" + "<br>" +
GmailApp.sendEmail(
toEmail, // recipient
subject, // subject
'test', { // body
htmlBody: message // advanced options
}
);
}
}
It works fine except that sometimes the input fields for email will be blank, in which case I need the script to ignore that supplier and continue to run. At the moment it is obviously hitting the empty input and stopping the execution.
I presume I need a conditional statement of sorts... something along the lines of if(hotelAddresses[i] != null) {}
But I cannot work out where to insert this...
Additional: 31 Aug 18
For the HTML I have a series of objects (33 in total) that are all set up like this:
<input type="checkbox" id="check1" class="check" checked>
<input type="text" id="name1" class="contactNameInput" name="toAddress1">
<input type="text" id="contactName1" class="contactNameInput mailName" name="contactName1">
<input type="text" id="time1" class="contactNameInput hidden mailTime" name="time1">
<input type="text" id="day1" class="contactNameInput hidden mailDay" name="day1">
<input type="text" id="date1" class="contactNameInput hidden mailDate" name="date1">
<textarea class="additional contactNameInput" id="additional1" name="additional1" placeholder="Additional requests..."></textarea>
<div class="preview1"></div>
You want to separate the cases with and without hotelAddresses[i] using a script like if(hotelAddresses[i] != null) {}. When my understanding is correct, how about this modification?
Modification points:
Do you want to add after "<span style='color:#0e216d'><b> Company name. </b>" + "<br>" +? In the current script, it's "<span style='color:#0e216d'><b> Company name. </b>" + "<br>" + GmailApp.sendEmail(...). If you want to add more strings, please put them. If you don't want to add, please remove the last +.
I think that the script of if(hotelAddresses[i] != null) {} can be used in the for loop.
The script which reflected above is as follows.
Modified script:
In this modified script, the script of for loop was modified.
for(var i = 0; i<times.length; i++) {
var toEmail = hotelAddresses[i];
if (toEmail) {
var subject = "subject";
var message = "messages";
GmailApp.sendEmail(toEmail, subject, 'test', {htmlBody: message});
} else {
// do something
}
}
Note:
In this modified script, subject and message are replaced by "subject" and "messages", respectively. So please modify them for your situation.
If you want to do something when hotelAddresses[i] is null, please modify // do something.
If you don't want to do something when hotelAddresses[i] is null, please remove else {}.
If I misunderstand your question, please tell me. I would like to modify it.

JSP Error Postgres connection

I am trying to establish a connection between JSP and Postgres. Unfortunately I only see the table with its columnms, the columnms are not filled. How can I put data into the columns?
My code:
<%# page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.* "%>
<%# page import="java.io.*"%>
<html>
<head>
<title>Films Example: JSP</title>
</head>
<body bgcolor="white">
<div>
<h1>Filmworld</h1>
<table border=1>
<tr>
<td>imdbID</td>
<td>name</td>
<td>year</td>
<td>rating</td>
<td>votes</td>
<td>runtime</td>
<td>actors</td>
<td>genres</td>
<td>directors</td>
</tr>
<%
try {
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://localhost:5432/movie";
String username = "postgres";
String password = "cemcan";
String myDataField = null;
String myQuery = "SELECT * FROM movie";
Connection myConnection = null;
PreparedStatement myPreparedStatement = null;
ResultSet myResultSet = null;
Class.forName(driver).newInstance();
myConnection = DriverManager.getConnection(url, username, password);
myPreparedStatement = myConnection.prepareStatement(myQuery);
myResultSet = myPreparedStatement.executeQuery();
out.println("<table border=1>");
while (myResultSet.next()) {
String imdbID = myResultSet.getString("imdbID");
String name = myResultSet.getString("name");
int year = myResultSet.getInt("year");
double rating = myResultSet.getDouble("rating");
int votes = myResultSet.getInt("votes");
int runtime = myResultSet.getInt("runtime");
String directors = myResultSet.getString("directors");
out.println("<tr><td>" + imdbID + "</td><td>" + name + "</td><td>" + year + "</td><td>" + rating
+ "</td><td>" + votes + "</td> <td>" + runtime + "</td> <td>" + directors + "</td> </tr>");
}
out.println("</table>");
myConnection.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
out.print("SQLException: " + ex.getMessage());
out.print("SQLState: " + ex.getSQLState());
out.print("VendorError: " + ex.getErrorCode());
}
%>
</table>
</div>
</body>
</html>
your code has at least two problems:
if you don't have the jdbc driver in the classpath the error goes
into the application server output since you have a line with
e.printStackTrace();. you can check if this is the case because in
the html generated by jsp you did not see the html <table
border=1>
the html is not correct you are putting a table element just after
a .. element. the elements taken ffrom the db do not need
an extra tables, thar are already rows. Using a tbody is more
appropriate
I see that this is an example and it's ok for learning, but in "production code" put the login on the server side (servlet, framework controller, etc) and use at least <%=... %> in jsp instead of out, it helps to separate page markup to program variables

C#. How to avoid image attached while sending mail

I am trying to send email from my.net application.
I have included an image in it. I get the image in the email. Issue is the image is coming also as an attachment.
I need only the inline image. Not attachment. Any option to remove the attachment?
I have include the code below
body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
body += "</HEAD><BODY><DIV><FONT face=Arial color=#ff0000 size=2>this is some HTML text";
body += "</FONT></DIV><DIV><img width=600 height=100 id=\"_x0000_i1028\" src=\"cid:cid1\" alt=\"KPMG LINK\"></DIV></BODY></HTML>";
AlternateView alternate = AlternateView.CreateAlternateViewFromString(body, null, "text/plain");
AlternateView alternateHtml = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
LinkedResource resource = null;
resource = new LinkedResource(ImagePath, new ContentType("image/png"));
resource.ContentId = "cid";
alternate.LinkedResources.Add(resource);
message.AlternateViews.Add(alternate);
message.AlternateViews.Add(alternateHtml);
smtp.Send(message);
Try from any one of below two options: (Reference)
Option 1:-
System.Net.Mail.Attachment inline = new System.Net.Mail.Attachment(#"imagepath\filename.png");
inline.ContentDisposition.Inline = true;
Option 2 :-
using (var client = new SmtpClient())
{
MailMessage newMail = new MailMessage();
newMail.To.Add(new MailAddress("you#your.address"));
newMail.Subject = "Test Subject";
newMail.IsBodyHtml = true;
var inlineLogo = new LinkedResource(Server.MapPath("~/Path/To/YourImage.png"));
inlineLogo.ContentId = Guid.NewGuid().ToString();
string body = string.Format(#"
<p>Lorum Ipsum Blah Blah</p>
<img src=""cid:{0}"" />
<p>Lorum Ipsum Blah Blah</p>
", inlineLogo.ContentId);
var view = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
view.LinkedResources.Add(inlineLogo);
newMail.AlternateViews.Add(view);
client.Send(newMail);
}

Getting Image path instead of Image - PhoneGap Listview

I am working on an PhoneGap application in which I am saving user's name , number and Email , after that I am displaying that data to another page in list - view. That has been done very successfully. But now when I want to store Image of user in my local Storage, I am getting the path of image instead of Image.
I am saving my data in this way :
<SCRIPT Language="JavaScript" charset="utf-8" type="text/javascript">
var userName, userNumber, userEmail, userImage ;
function showAndClearField(frm)
{
userName = frm.name.value;
userNumber = frm.number.value;
userEmail = frm.email.value;
if (frm.name.value == "" )
{
alert("Please enter your name!")
}
else if(frm.number.value == "")
{
alert("Please enter your number!")
}
else if(frm.email.value == "")
{
alert("Please enter your Email !")
}
else
{
alert("Name : " + userName + '\n' + " Number: " + userNumber + '\n' + " Email: " + userEmail )
frm.name.value = ""
frm.number.value = ""
frm.email.value = ""
var db = window.openDatabase("TestingDemo", "1.0", "PhoneGapTesting Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
function populateDB(tx)
{
tx.executeSql('INSERT INTO DEMO (id, data, userName, userNumber, userEmail, userImage) VALUES (1, "Third row", "'+ userName +'" , "'+ userNumber +'" , "'+ userEmail +'", "'+ userImage +'")');
}
While displaying data I am using following code :
var nameOfUser , numberOfUser , emailOfUser, imageOfUser;
for (var i=0; i<len; i++)
{
nameOfUser = results.rows.item(i).userName;
numberOfUser = results.rows.item(i).userNumber;
emailOfUser = results.rows.item(i).userEmail;
imageOfUser = results.rows.item(i).userImage;
numArr.push({ name : nameOfUser , number : numberOfUser , email : emailOfUser, image : imageOfUser });
}
function createCheckboxes(){
$("#createBtn").remove();
$("#content").append('<fieldset id="cbFieldSet" data-role="controlgroup" style = "padding : 20px" >');
var length = numArr.length;
for(var i=0;i<length;i++)
{
$("#cbFieldSet").append('<input type="checkbox" name= "cb-'+i+'" id="cb-' + i +'" number = "'+numArr[i].name+'"/> <label for= "cb-'+i+'">' + "Name : " + numArr[i].name + ' <br>' + "Email : " + numArr[i].email +' <br>' + " Number " + numArr[i].number +' <br>' + numArr[i].image + ' <br><br> </label>' );
alert("List Created !");
}
alert("Out of For loop !");
$("#content").trigger("create");
alert("Content Created !");
$("#showBtn").css("visibility","visible");
}
function showSelectedNames(){
var count = $("#cbFieldSet input:checked").length;
var str = '';
for(i=0;i<count;i++){
str += ' '+$("#cbFieldSet input:checked")[i].value;
}
alert("You selected----"+str);
}
</script>
How the view I am getting is :
i do not know about this particular program,
but i do know that you are passing the image location as an argument, (text).
the other arguments are also text, and you have no done anything differently with the image argument to have the UI display an image. maybe you are missing image tags, or an "getImage(location)" type function.
edit:
<img src="PATH" />
you need to put PATH as image location and this is what will display it.