How to send mail in c# instantly or at least perform it in background [closed] - c#

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am using smtp client and mail message class of c# in order to send mail. The mail is to be send to one or at most two users at a time. However, the mail sending process is slow. it takes almost 5-8 second to send mail. Till this time, the page remains in idle position. Is there a way in asp.net c# to send mail instantly or at least redirect to another page and perform the mail sending operation at background so that user do not feel delay. Any suggestions!! I had done research on smtpclient.sendmailAsync but in using this property, mail was not send.. Thanks in advance

Task sendEmail = new Task(() =>
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("me#mycompany.com");
mail.To.Add("you#yourcompany.com");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is a sample body";
//send the message
SmtpClient smtp = new SmtpClient();
smtp.Port = 465;
smtp.UseDefaultCredentials = true;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("youGmailAddress#gmail.com", "YourPassword");
smtp.Send(mail);
});
sendEmail.Start();

Related

avast VS my Programm

I have problem with my program. I make a simple mail-messenger, and in this code :
var mail = new MailMessage();
var smtpServer = new SmtpClient("smtp.mail.ru");
smtpServer.Port = 25;
smtpServer.Credentials = new
NetworkCredential("#mail.ru", "pass");
smtpServer.EnableSsl = true;
mail.Body = text;
mail.From = new MailAddress("#mail.ru");
mail.To.Add("#mail.ru");
smtpServer.Send(mail); // in this moment
Avast find the idp generic in moment of mail send. The other antiviruses (eset32, Kaspersky,cureit) do not see problems and danger in code. I also was try to send mail with mailkit.dll. how can I fix it?
Your best bet is probably using the standard SMTP client-to-server email submission port: 587.
smtpServer.Port = 587;
If you, for whatever reason, can't use the standard email submission port, use the Avast GUI to make exceptions. Doing it through the antivirus directly should allow your program to run on your machine, and that's all you want, right? ;)
You can try:
Excluding your build directory from live scans
Authorizing your process to use port 25
Avast help pages for further reading

How to send email in windows 10 apps using C#? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am working on a Windows 10 store app project. In my project I need to send confirmation email to client using my app. How can I do it without using any confirmation dialogue to show to user?
Confirmation email is like
"You order no "xy" has been confirmed."
using System.Net.Mail;
...
MailMessage mail = new MailMessage("you#yourcompany.com", "user#hotmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
reference: Send email with C#
Also as mentioned in the comments see this : MSDN Docs Send Email

cancel Send mail using smtp SMTP

In my application, I'm using SmtpClient for sending emails(only from gmail accounts). everything is fine and perfect.
I Saw an option in gmail that allows us to cancel/undo the send mail. as shown in the below image.Here my question is regarding that, how can i cancel/undo the send mail from my program based on some conditions.
following is the code i'am using for sending mail:
MailMessage mail = new MailMessage("frommail#company.net", "mail#gmail.com");
SmtpClient client = new SmtpClient();
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("frommail#company.net", "xxxxxxx");
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
// this is what i want to do
if(someCondition=true)
{//undo the send operation}
From my limited knowledge, you cannot cancel a mail that was sent to a mail server. You can accomplish the undo functionality by:
Save the mail details in a table (lets call it pending_emails) on your server
A (delayed job is scheduled) or (recurring job runs every X minutes) and queries pending_emails for entries made 5 minutes earlier and sends them to the smtp server (as you are doing now)
The job sends the email and deletes the email from pending_emails
The undo button deletes the email from pending_emails
Google just delays the send of the email by 30 seconds, easiest way to do it yourself is an async timer of 30 seconds before sending it via smtp or using a filter before sending.

Issue in receiving emails [duplicate]

This question already has answers here:
The SMTP server requires a secure connection or the client was not authenticated
(3 answers)
Closed 8 years ago.
I am doing my project in mvc4 using c#. I have a contact page i my website. My need is that i have to receive messages to my email id from other id's, when clicking the Send button.I use the following code
public void ReceiveMail(string name,string email,string message)
{
MailMessage msg = new MailMessage();
HttpContext ctx = HttpContext.Current;
msg.To.Add(new MailAddress("MyEmailId"));
msg.From = new MailAddress(email);
msg.Subject =name + "send a message";
msg.Priority = MailPriority.High;
msg.Body = message;
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");// i am confused what to write here
SmtpServer.Send(msg);
}
It shows the error
The SMTP server requires a secure connection or the client was not authenticated.
The server response was: 5.7.0 Must issue a STARTTLS command first.
at4sm42219747pbc.30 - gsmtp
I don't know from which server i got the mail. Then how can i solve this issue . Please help me
Sending emails with Gmail requires some additional settings. At first, port number should be 587 (instead of default 25). At second, Gmail requires secure connection. And of course you should provide valid credentials.
All in all, initialization of SmtpClient should look like this:
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com", 587);
SmtpServer.EnableSsl = true;
SmtpServer.Credentials = new NetworkCredential("username#gmail.com", "password");
as the error says, a STARTTLS command should be used first. Thas means gmail only accepts mail via secure connection. In this answer enableSsl was set to true. As the documentation from microsoft says, the SmtpClient class has such an property too. Furthermore you should leave your credentials in the smptClient. I think gmail only accepts mail from authenticate users. I think the whole problem is solved here.
You need to use NetworkCredential to login into Gmail SMTP server. Error is very apparent.
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("your-email", "your-password");
Have you tried:
smtpServer.Host = "smtp.gmail.com";
smtpServer.Port = 587;
smtpServer.Credentials =
new NetworkCredential("SenderGmailUserName", "SenderPassword");

how to use mailing system in C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to have an email system , when user done an action after that someone recieve an email in C#
so now how I can do that ??
You could use the .Net SmtpClient class as follows:
using System.Net.Mail;
// the e-mail details
String from = "me#server.com";
String to = "someone#server.com";;
// build up the message
MailMessage message = new MailMessage(from, to);
message.Subject = "My Title";
message.Body += "This is the biody of my message";
// create a server pointing to your mail server
String server = "mail.server.com";
// create a client
SmtpClient client = new SmtpClient(server);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
// send the message
client.Send(message);
To send an email in .NET you could use the SmptClient class.

Categories

Resources