In the EWS, I found that in a saved draft EmailMessage m, people could use m.DisplayTo to get receipt's name, but no property to display email address. Then how and where can I get the receipt's email address and ccRecipt's email address, assume that recipt and ccRecipt are not null in the draft.
Use the ToRecipients and CCRecipients properties. They are collection of EmailAddress instances.
Related
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
I want to use the email address that is stored in a SQL Table (Memberships), the one created by Visual Studio when you build a website. NB: Not an MVC Site, just a regular webform
Say for instance, If i am logged into the website, with my username and password --> it recognises me as the user X. Bearing in mind user X has a user name, password, email address.
Now, during the application i want to press a submit button which sends an email BUT i want it to use user X's email address as the FROM address.
Part of submit button:
MailAddress to = new MailAddress(nameddl.Text);
MailAddress from = new MailAddress("User X's email address");
MailMessage message = new MailMessage(from, to);
Example of SQL Table:
ID -- Username -- Email Address -- Password
1 -- UserX -- userx#x.com -- password
I am struggling to find a way to insert a variable or something that contain the logged in user's email address in this line without manually typing in their address -->
MailAddress from = new MailAddress("User X's email address");
Can anyone show me a way to do it please?
You should be able to do something like this:
var currentUser = Membership.GetUser(User.Identity.Name);
var userEmail = currentUser.Email;
See Membership.GetUser
MailAddress from = new MailAddress(userEmail);
Seems to be work for sessions ;)
http://msdn.microsoft.com/en-us/library/vstudio/ms178581(v=vs.100).aspx
Session["mail"] = new MailAddress("...");
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));
From an AddressEntry instance I'm calling GetExchangeUser or GetExchangeDistributionList methods to get PrimarySmtpAddress. This works fine when the AddressEntry has a DisplayType of olUser or olDistList, but both return null for an address with DisplayType of olForum.
The Exchange address does have an associated SMTP address. In Outlook I can type the address into "To" on a new email and it resolves to the appropriate Exchange user. Double-click on the user and an SMTP address does show. I just can't find a way to get to it through the Outlook object model.
If the SMTP address is available on that address entry, you should be able to retrieve it using AddressEntry.PropetyAccessor.GetProperty.
Take a look at that address entry using OutlookSpy (I am its author) - if you already have a message with that GAL entry as one of the recipients, select it in Outlook, click IMessage button on the OutlookSpy ribbon, go to the GetRecipientTable tab, double click on the recipient.
Do you see PR_SMTP_ADDRESS property? How about PR_EMS_AB_PROXY_ADDRESSES? Both properties can be retrieved using AddressEntry.PropetyAccessor.GetProperty
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.