C# e-mail issue - c#

I have this help desk application which sends an e-mail to me with a specific issue. The user is required to input his e-mail address into a textbox. What I'd like to do is for the user to get a copy of the problem as well.
MailMessage req_mail = new MailMessage(reqMail.Text, "system.admin#home.com");
Where reqMail.Text is the user's e-mail address.
Any ideas why it doesn't work? Because I can see from who it is...

The overload of the MailMessage constructor you're using takes a from and a to address.
You've supplied the users email as the from and your email as to. AFAIK, there isn't a constructor for CC'ing or BCC'ing.
Instead you just need to do this:
req_mail.Bcc.Add(new MailAddress(reqMail.Text));
Or:
req_mail.CC.Add(new MailAddress(reqMail.Text));
If you prefer.

According to the constructor you're using that MailMessage is from the user, not to the user. If you want to send the message to the user then their address would need to be in the To or CC or BCC parts of the message. Something like:
var req_mail = new MailMessage(reqMail.Text, "system.admin#home.com");
req_mail.CC.Add(new MailAddress(reqMail.Text));

Related

sending email to multiple addresses,but not see other user addresses

I am using the SmtpClient in C# and I will be sending to potentially 1000s of email addresses.
I want to only the recipient's email address is displayed.
for example:
I send email to aa#xx.xx,bb#xx.xx,cc#xx.xx,dd#xx.xx...
aa can only see the email address aa#xx.xx,bb can only see the email address bb#xx.xx.
they don't know I send the email to others.
Use mail.BCC instead of mail.To for users who's addresses you dont't want to display to others

ASP.NET send mail to multiple users

Hello i have a problem with sendig mails from asp.net web site. Here is my code
private void mailgonder(string mail, string adsoyad)
{
MailMessage mm = new MailMessage();
mm.From = new MailAddress("my mail address", "my name");
mm.Subject = "YENİ DUYURU";
mm.Body = "Sistemde okumadığınız yeni bir duyuru bulunmaktadır.";
mm.To.Add(new MailAddress(mail, adsoyad));
SmtpClient sc = new SmtpClient("my smtp client");
sc.Port = 587;
sc.Credentials = new NetworkCredential("my username", "my password");
sc.Send(mm);
}
I want to send mail to 1500 users with same time. How can i do this in asp.net (we will have over 1000 member in this web project)
I can send like this to one person. But i don't know how can i send this to multiple persons
Thanks
As MailMessage.To is a collection, you can add as much as you want :
mm.To.Add(new MailAddress("user#user.com", "user1"));
mm.To.Add(new MailAddress("user1#user.com", "user2"));
mm.To.Add(new MailAddress("user2#user.com", "user3"));
mm.To.Add(new MailAddress("user3#user.com", "user4"));
.....
until
mm.To.Add(new MailAddress("user1499#user.com", "user1499"));
mm.To.Add(new MailAddress("user1500#user.com", "user1500"));
NOTE :
Restrictions may exist according to your mail server or access provider. For more efficiency, use a mailing list.
You have to send each user seperate emails. Do not, never, add more than 1 address to TO unless you have sender score certification, doing opposite will cause you get banned from mail providers since they would think you are a spammer. And also spam list is global, which means if you get banned from gmail, you will also get banned from hotmail or yahoo in a short period of time.
Just select for example 20 email addresses from database each time and loop that 20 and call your mailgonder method for each.
Other than what I wrote above, if you write multiple TO's, each of your users will see each others email adressses which is not cool from user perspective.
I Believe the simplest approach by far is to make a contact group. Doing this will keep the amount of code written to a minimum. Here is a link explaining how to do so in Outlook How to make a contact group
Once you have the contact group setup, simply do this:
String Devemail = "devgroup#whatever.com";
MailMessage message = new MailMessage();
message.To.Add(Devemail);
//The rest of your code here
The rest of your code will work fine.
If someone has a better/simpler approach, please feel free to correct me.
EDIT: I am kind of shocked that we recommend he hard code 1500 email addresses into his code. Can someone give me a good reason for using that approach over using an email group?

Sending emails on behalf of user

So im implementing a mailservice in our webapp that users can utilize to send out emails to persons on a certain list. Now i need to know how to best use the System.Net.Mail object to send mail on the users behalf. Ive been trying this now for a while without the right results.
I would like the mail to read "our system on behalf of user 1" and the reply to adress should be the adress that user1 has in our system so that when the contacted person wants to reply to the mail he should get user1:s address, not ours. How can I do this?
Which fields do I need to declare and how? This is how i have it set up right now, but a reply to these settings sends a mail back to noreply#oursystem.com
from = 'noreply#oursystem.com'
replyTo = 'user1#privateaddress.com'
to = 'user1#privateaddress.com'
sender = 'user1#privateaddress.com'
cc = ''
ReplyTo is obsolete. You should use ReplyToList
Example:
MailAddress mailFrom = new MailAddress("noreply#oursystem.com");
MailAddress mailTo = new MailAddress("user1#privateaddress.com");
MailAddress mailReplyTo = new MailAddress("user1#privateaddress.com");
MailMessage message = new MailMessage();
message.From = mailFrom;
message.To.Add(mailTo); //here you could add multiple recepients
message.ReplyToList.Add(mailReplyTo); //here you could add multiple replyTo adresses
This was caused by a programming error on the receiving end. The correct solution is to set the from and replyto as above. That will get the correct behaviour.

How can I send emails to multiple recipients using a MailDefinition

I'm creating a new mail definition using the CreateMailMessage function of a MailDefinition. One of the required parameters is recipients. The documentation for this function states that recipients is to be a comma-separated list of recipients, however when I try to send a message to multiple users I am getting the following error:
An invalid character was found in the mail header: ','...
So it seems like this function is not working as intended. Normally I would add all the recipients to the mail message itself, but unfortunately the recipients parameter is required and cannot be left blank. Any ideas?
I got it working but unfortunately its more of a hack than anything.
I take one email address from the "to" field and set it as the recipient in CreateMailMessage, which returns a MailMessage instance.
I take the produced MailMessage and add all the email addresses in my MailAddressCollection by iterating through the construct. I also do this for all CC'd users.

asp.net mailmessage BCC and CC won't work

Does anyone see anything wrong with this code:
MailMessage msg = new MailMessage();
msg.From = new MailAddress(WebConfigurationManager.AppSettings.Get("ReservationsFrom"));
msg.ReplyTo = new MailAddress(myRes.Email);
msg.To.Add(new MailAddress(WebConfigurationManager.AppSettings.Get("ReservationsTo")));
msg.CC.Add(new MailAddress(WebConfigurationManager.AppSettings.Get("ReservationsBcc")));
Try as I might, I can only get the 'To' address and the "ReplyTo" to work, the CC and the BCC never receive mail, even if I hard code the addresses in.
Am I missing something obvious here?
Edit: And yes, I am sure I am pulling the right addresses out of the web.config - like I said, even if I hard code a static address the BCC and CC never received email.
I had similar problem and checked the smtp log. Looks like .net sends only one message, if "To" and "Cc"/"Bcc" adress are same.
If static addresses hard-coded into the method calls aren't working, you're having a problem with delivery, not the addresses.
Can you telnet to port 25 on the smtp host you're using? Can you send an email to the test addresses from a regular email client (not web-based)?

Categories

Resources