I wrote a C # email sending program that works fine. In addition, I have a PHP script to send emails that work great.
But my question is: Is it possible to send an email from C #, like in PHP, where you do not need to specify credentials, server, ports, etc.
I would like to use C # instead of PHP because I am building an ASP.Net web application.
This is my current C # code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Mail; using System.Net; namespace $rootnamespace$ { public partial class $safeitemname$ : Form { public $safeitemname$() { InitializeComponent(); } private void AttachB_Click(object sender, EventArgs e) { if (AttachDia.ShowDialog() == DialogResult.OK) { string AttachF1 = AttachDia.FileName.ToString(); AttachTB.Text = AttachF1; AttachPB.Visible = true; AttachIIB.Visible = true; AttachB.Visible = false; } } private void AttachIIB_Click(object sender, EventArgs e) { if (AttachDia.ShowDialog() == DialogResult.OK) { string AttachF1 = AttachDia.FileName.ToString(); AttachIITB.Text = AttachF1; AttachPB.Visible = true; } } private void SendB_Click(object sender, EventArgs e) { try { SmtpClient client = new SmtpClient(EmailSmtpAdresTB.Text); client.EnableSsl = true; client.Timeout = 20000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(EmailUserNameTB.Text, EmailUserPasswordTB.Text); MailMessage Msg = new MailMessage(); Msg.To.Add(SendToTB.Text); Msg.From = new MailAddress(SendFromTB.Text); Msg.Subject = SubjectTB.Text; Msg.Body = EmailTB.Text;
Here's how to do it in PHP:
<?php --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: application/zip; name="Doc1.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php
I am not asking you to write your code, but perhaps you could provide some information or let me know if this is possible or not.
Edit:
My question is not to not use the SMTP server, but how to send an email without entering a username and password. I know that it will only work if the request to send a message comes from my server.
Creator
source share