I am trying to send something below in the html body of email. Tried space tag but it is NOT like tab character. I wanna know if there is a way to use tab character in the html email body in order to look tidy?
CSS is used for presentation in HTML. Use
margin or padding depending on your current deign. You'll also need to use a fixed width font. Otherwise; text blocks may not line up as expected.
I tested the string in your first post and found format errors. Try using the literal operator and the string builder which let's you visualize the report in code.
I am producing the string as follows and display it on the screen, then a user clicks the send e-mail button.
[HttpGet]
public IActionResult A101Pin(int quantity, string game, string email, int prc)
{
try
{
string result = null;
Random rnd = new Random();
DemoList dList = new DemoList();
int price = 0;
if (prc > 0)
{
price = prc;
}
for (int i = 0; i < quantity; i++)
{
if (game == "ZULA")
{
result = result + "* " + game + "\t\t\tSerial: " + rnd.Next(100000000, 999999999) + "\tPin: " + rnd.Next(100000000, 999999999) + "\tPrice: 5\n";
price = price + 5;
dList.price = price;
dList.gameList = result;
}
else if (game == "STEAM")
{
result = result + "* " + game + "\t\t\tSerial: " + rnd.Next(100000000, 999999999) + "\tPin: " + rnd.Next(100000000, 999999999) + "\tPrice: 10\n";
price = price + 10;
dList.price = price;
dList.gameList = result;
}
else if (game == "GAMEFORGE")
{
result = result + "* " + game + "\tSerial: " + rnd.Next(100000000, 999999999) + "\tPin: " + rnd.Next(100000000, 999999999) + "\tPrice: 6\n";
price = price + 6;
dList.price = price;
dList.gameList = result;
}
else if (game == "PUBG")
{
result = result + "* " + game + "\t\t\tSerial: " + rnd.Next(100000000, 999999999) + "\tPin: " + rnd.Next(100000000, 999999999) + "\tPrice: 10\n";
price = price + 10;
dList.price = price;
dList.gameList = result;
}
else if (game == "LOL")
{
result = result + "* " + game + "\t\t\tSerial: " + rnd.Next(100000000, 999999999) + "\tPin: " + rnd.Next(100000000, 999999999) + "\tPrice: 12\n";
price = price + 12;
dList.price = price;
dList.gameList = result;
}
}
return new JsonResult(dList);
}
catch (Exception e)
{
var timestamp = DateTime.UtcNow;
//NLOG
NLog(logger2, "A101 " + e.Message, timestamp, 0);
throw new Exception(e.Message);
}
}
public bool SendEmail(string message, string email, string total)
{
try
{
var messagem = new MimeMessage();
messagem.From.Add(new MailboxAddress("test", "test@test.com"));
messagem.To.Add(new MailboxAddress("Customer", email));
messagem.Subject = "Serial";
messagem.Body = new TextPart("plain")
{
Text = message
};
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.yandex.com.tr", 587, false);
//SMTP server authentication if needed
client.Authenticate("test@test.com", "test");
client.Send(messagem);
client.Disconnect(true);
return true;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
Here is how I display it on the page:
(function () {
'use strict';
window.addEventListener('load', function () {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function (form) {
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
} else {
event.preventDefault();
var selText = $("#validationCustom04").val();
var quantity = $("#quantity").val();
var email = $("#email").val();
var price = $("#total").val();
if ($("#total").val() != '') {
price = $("#total").val();
}
var serviceURL = '/GameBanks/A101Pin?quantity=' + quantity + '&game=' + selText + '&email=' + email + '&prc=' + price;
$.ajax({
type: "GET",
url: serviceURL,
dataType: 'json',
success: function (data) {
//alert(JSON.stringify(data));
ShowResult(data);
}
});
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
function ShowResult(data) {
$('#result').append(data.gameList);
$('#total').val(data.price);
}
Here is how I call action to send mail:
$("#btn_purchase").click(function() {
var result = $("#result").val();
var total = $("#total").val();
var email = $("#email").val();
alert(result);
var serviceURL = '/GameBanks/Send';
$.ajax({
type: "GET",
url: serviceURL,
dataType: 'json',
data: {
body: result,
total: total,
email:email
},
success: function (data) {
if(true)
alert("Email sent to " + email);
else
alert("Email did not send to " + email);
}
});
});
Member
527 Points
2728 Posts
HTML mail body question?
Mar 14, 2020 01:22 PM|cenk1536|LINK
Hello,
I am trying to send something below in the html body of email. Tried space tag but it is NOT like tab character. I wanna know if there is a way to use tab character in the html email body in order to look tidy?
I am replacing "/n" with "<br/>" before sending mail.
Best Regards.
All-Star
53021 Points
23607 Posts
Re: HTML mail body question?
Mar 14, 2020 01:58 PM|mgebhard|LINK
CSS is used for presentation in HTML. Use margin or padding depending on your current deign. You'll also need to use a fixed width font. Otherwise; text blocks may not line up as expected.
Another option is an HTML table;https://www.w3schools.com/html/html_tables.asp.
Yet another option is a plain text email which works well with white space characters like \t, \r , and \n.
Member
527 Points
2728 Posts
Re: HTML mail body question?
Mar 14, 2020 03:46 PM|cenk1536|LINK
I tried plain text but unfortunately, it's not what I expected.
https://ibb.co/BTZ4FGJ
All-Star
53021 Points
23607 Posts
Re: HTML mail body question?
Mar 14, 2020 05:25 PM|mgebhard|LINK
I tested the string in your first post and found format errors. Try using the literal operator and the string builder which let's you visualize the report in code.
Don't forget the font must be fixed width.
Again you can use standard HTML (a table) to format the report too. In the future, share your latest code if you want a community code review.
Member
527 Points
2728 Posts
Re: HTML mail body question?
Mar 14, 2020 05:48 PM|cenk1536|LINK
I am producing the string as follows and display it on the screen, then a user clicks the send e-mail button.
Here is how I display it on the page:
Here is how I call action to send mail:
Here is the cshtml:
All-Star
53021 Points
23607 Posts
Re: HTML mail body question?
Mar 14, 2020 09:49 PM|mgebhard|LINK
I'm not sure if you are still having a problem. What is clear is you did not follow the advice.
Member
527 Points
2728 Posts
Re: HTML mail body question?
Mar 15, 2020 12:48 PM|cenk1536|LINK
I used HTML table, thank you.