I have developed code,in C#, which sends email in Lotus Notes.
I want SentBy(From field) in the email to be hidden. I have user the Principal field to make Custom field.
NotesDocument doc = db.CreateDocument();
doc.ReplaceItemValue("Form", "Memo");
doc.ReplaceItemValue("SendTo", richTextBox1.Text.Trim().Split(','));
doc.ReplaceItemValue("Subject", richTextBox3.Text);
doc.ReplaceItemValue("Principal", "Test Demo");
NotesRichTextItem _richTextItem = doc.CreateRichTextItem("Body");
_richTextItem.AppendText(richTextBox4.Text + "\r\n");
doc.SaveMessageOnSend = true;
if (this.check)
doc.Send(false);
MessageBox.Show("Mail Sent successfully");
The above code sends email perfectly but it doesn't hide the SentBy (From field). Sent By ( From field) always shows the name of the person running this code along with the Principal. Can this be hidden so that only the Principal field, here Test Demo, is only visible.
It can't be hidden if you're using the NotesDocument.Send() method. (IBM Domino is an enterprise email system, so it doesn't make spoofing senders easy.)
It can be hidden if you write the message directly to the Domino server's mail.box file. That's not supported by IBM, though, so if you do that you're on your own if you do anything that screws up email routing and delivery. You can find a link to sample code that does it, though, in one of the answers to this older question.
Related
I am developing a software which send email after the user pressed a button.
I encounter some issues with these emails: they sometimes raise this exception: The specified string is not in the form required for an e-mail address.. I emphasise on sometimes because they actually works sometimes.
Surprising thing is that the mail addresses are actually correctly formatted: they all look like blahblah#domain.com or Blah Blah <blahblah#domain.com>. This even happens with some of my company's mails, which - of course - are valid. I even checked all the addresses with this regex and they all passed: ^\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*$.
Here are the steps my software is going through:
Add the main address:
var mail = new MailMessage(new MailAddress("logistics#company.com", "company logistics department"), new MailAddress(address));
Here the address is valid since the software did send an email to this address prior to this step.
In a loop I add the CCs addresses:
mail.CC.Add(new MailAddress(email));
Here I applied a null/empty check so I am not adding any empty mail address.
And finally I add myself in BCC address:
mail.Bcc.Add("my#company.com");
Is there any issue in the way I'm doing this ?
Are there some known issues (additionnaly random ones) about the C# .NET mail class?
Is there a limit on the maximum amount of To / CC / Bcc addresses this class can handle ?
EDIT: i'm using System.Net.Mail classes
I own a domain, example.com. I'd like to send out emails from my webapp where it displays it's from info#example.com, or support#example.com.
I've used SendGrid a lot in the past from within my websites, but I've always simply been able to fill out where an email is from by editing the From property of the SendGridMessage class, and it just showed up that way on clients.
Is there an official way/API from sendgrid to utilize a domain that I own? What's to stop me or someone else from typing any domain they want using the sendgrid API?
The process of setting up DNS records for your domain that allow your emails to be authenticated, as well as verifying your ownership of the domains, is known at SendGrid as whitelabeling. After this process, SPF and DKIM records will then be available for receiving servers to check.
SPF and DKIM ensure the originating IP is allowed to send email on behalf of the domain in question, and to essentially verify that the contents of the email have not been tampered with respectively.
The thing that will stop others from sending from your domain is called DMARC. Domains owned by yahoo, aol, and very soon google all implement strict policies; emails claiming to be from these domains but that are not will never be delivered. Many other domains will soon be following this trend and implementing DMARC.
The code sample from https://azure.microsoft.com/en-us/documentation/articles/sendgrid-dotnet-how-to-send-email/ shows how to do this:
// Create the email object first, then add the properties.
var myMessage = new SendGridMessage();
// Add the message properties.
myMessage.From = new MailAddress("john#example.com");
// Add multiple addresses to the To field.
List<String> recipients = new List<String>
{
#"Jeff Smith <jeff#example.com>",
#"Anna Lidman <anna#example.com>",
#"Peter Saddow <peter#example.com>"
};
myMessage.AddTo(recipients);
myMessage.Subject = "Testing the SendGrid Library";
//Add the HTML and Text bodies
myMessage.Html = "<p>Hello World!</p>";
myMessage.Text = "Hello World plain text!";
I'm currently trying to use Selenium Webdriver (C#) to automate a Forgot Password -> Reset Password workflow, where the user navigates to a page and supplies their username, and the backend code validates the username, then sends an email with a reset password link to the email address associated with their account.
I'm able to automate the process up to the point where the code sends the email, but I don't know any ways of checking for the email and/or clicking a link in the email, so I was hoping someone more experienced with Selenium/automation may be able to give me a few pointers.
Ideally the test should not care about the email address that the email is being sent to. Is there a way for Selenium WebDriver or some 3rd party package to catch the email being sent?
Thanks for any input or suggestions.
No. You are talking about setting up an email server, which is not an easy task.
You should send it to a test work email (if this is for a company), or a public email (hotmail/gmail), or if security is not an issue at all, the easiest place to send it would be a disposable email (mailinator)
You could try PutsBox. You can send an email to whatever-you-want#putsbox.com, wait for a few seconds (SMTP stuff ins't instantaneous) then check your email via http://preview.putsbox.com/p/whatever-you-want/last.
Have a look at this post tutorial, it can give you some ideas.
There is no integration of selenium with email clients like Thunderbird/Outlook. But if you have a web interface of the same email client, then you can access the email from browser and using selenium you can read and respond to the emails. I have tried this recently and it works fine where I have used web Outlook for testing.
Hope this helps.
Hi I was in a similar situation and was able to successfully implement a way to get an activation or forgotten password links.
Using Java Mail API I was able to trigger a method when such action is performed which goes into a Folder and read a specific message line then get the link and open it up in a browser using WebDriver.
However the main drawback with this is the inconsistency of reading a specific folder, sometimes emails goes to spam or other folder (in case of Gmail the new Social Folder) making it invisible or difficult to be retrieved.
Overall i think its a process that shouldn't really be automated, In terms of testing it should be done more code base level by mocking responses.
Snippet below should give you an idea on how to go about implementing
public class RefactoredMail {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("imap.gmail.com", "username", "password");
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message msg = inbox.getMessage(inbox.getMessageCount());
Address[] in = msg.getFrom();
for (Address address : in) {
System.out.println("FROM:" + address.toString());
}
Multipart mp = (Multipart) msg.getContent();
BodyPart bp = mp.getBodyPart(0);
System.out.println("SENT DATE:" + msg.getSentDate());
System.out.println("SUBJECT:" + msg.getSubject());
System.out.println("CONTENT:" + bp.getContent());
System.out.println("Activation Link:" + ((String)
bp.getContent()).startsWith("http"));
String [] line = new String[1];
line [0] = mp.getContentType().toString();
System.out.println("Activation Link:" + (mp.getBodyPart(0).getLineCount()));
System.out.println("Activation Link:" +line[0]);
} catch (Exception e) {
e.printStackTrace();
}
//WebDriver Stuffs
public String activationUrl() {
//getting the url link and making it a global variable .... etc
//Accessing the link
}
}
You can use https://github.com/cmendible/netDumbster or http://ndumbster.sourceforge.net/default.html. I've used one i forget which. This will host an smtp listener and allow you to make assertions against any email it receives. Its kind of awesome! The caveat is you need to be able to control where the server delivers mail in the environment you are testing.
I’m trying to create an event in my Microsoft Outlook calendar by using iCalendar standard. I’ve sent an email with content type “text/calendar” to my Exchange mailbox from .NET application.
It arrives to Outlook as an meeting request. Everything looks good, till the moment when I click the received meeting request, Outlook displays it as an empty calendar view with the text: “Meeting cannot be found in the calendar”.
I don’t understand why – I wanted to create an event and it is trying to find some existing?
If I send exactly the same email to whoever participant of the meeting except the organizer, it creates an event in their calendars and everything seems to be ok.
I’ve found that it is caused by the “ORGANIZER” property. If it is set to organizer’s email (my email) and I send meeting request to myself, an event is not created with the information “Meeting cannot be found in the calendar”.
So the question is why it doesn’t create an event for organizer? Organizer must have that event created to be notified by other participants if they have accepted or cancelled the meeting.
Here is the iCalendar:
BEGIN:VCALENDAR
PRODID:-//Company//Product 3.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20130225T200000Z
DTEND:20130225T203000Z
DTSTAMP:20130225T143039Z
ORGANIZER;CN="John Doe":mailto:john.doe#domain.com
UID:20130225T143039Z#domain.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;RSVP=TRUE;CN="John Smith"
;X-NUM-GUESTS=0:mailto:john.smith#domain.com
CLASS:PUBLIC
CREATED:20130225T143039Z
DESCRIPTION:
LAST-MODIFIED:20130225T143039Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Booking test
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
Let’s say that organizer want to create an meeting for 2 attendees. He fills in a form in the booking system.
The booking system sends email containing iCalendar standard to himself and to 2 meeting attendees.
This scenario doesn’t work.
It is not possible to create an event (cancellable meeting object) in the calendar of the organizer. The client thinks that email containing iCalendar format is just notification for attendee of the meeting already created in the organizer calendar. If such an email arrives to organizer’s mailbox, client app doesn’t create an event in the organizer’s calendar. It assumes that an event was created by organizer himself. E.g.: Outlook tells you in that case that “Meeting cannot be found in the calendar”.
If you ask Microsoft support about it, they only tell you that they does not support open standards: http://support.microsoft.com/kb/2269506
Working solution to this problem is to use platform services (Exchange Web Services or Google Calendar API) to create an event in the organizer’s calendar. Forget iCalendar standard.
The services can be configured for sending notifications to attendees automatically.
So it is enough to pass “SendInvitationsMode.SendToAllAndSaveCopy” if you’re using EWS:
Appointment appointment = new Appointment(service);
appointment.Subject = "Status Meeting";
appointment.Body = "The purpose of this meeting is to discuss status.";
appointment.Start = new DateTime(2014, 3, 1, 9, 0, 0);
appointment.End = appointment.Start.AddHours(2);
appointment.Location = "Conf Room";
appointment.RequiredAttendees.Add("user1#contoso.com");
appointment.RequiredAttendees.Add("user2#contoso.com");
appointment.OptionalAttendees.Add("user3#contoso.com");
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
or set “sendNotifications” parameter to true in case of Google Calendar API.
You don’t need to send an email to every particular attendee.
This is a bit of an old issue, but i think it is caused from using
METHOD:REQUEST
This marks that the ical should be updated, not that it is a new item. Instead, use
METHOD:PUBLISH
I can confirm that this works with DDay.iCal and Outlook Calendars.
This drove me mad for a week, so it is nice to see someone else confirming what I suspected. There is actually a relatively simple solution, which solves the question, although it is not very elegant. I can understand why one would not be allowed to take the role of Organiser from an outside source, but it is annoying that you can't.
Send out 2 invites. One to yourself (or whoever the organiser is) and then a different one to everyone else.
The one to yourself should have something else other than you down as the ORGANSISER, e.g. ORGANIZER:donotreply#outlook.com
The one to everyone else should have your email down as the organizer.
For this approach to work, you should set METHOD:REQUEST. If you set it to PUBLISH you will get duplicates on updates.
This approach means you get the meeting in your diary and you also get replies (to get replies you need to include the following line for each attendee:
ATTENDEE;CN="The Name";RSVP=TRUE:mailto:the_email#address.com.)
Note that the UID is the same for both versions of the file. It helps if the ORGANISER gets the Invite first so they can accept it before they start getting replies, otherwise people will be replying to something that effectively does not yet exist. That wont stop them accepting the invite, but it might be a little confusing for the ORGANIZER. To help with this I put in a slight delay between email 1 and 2.
I would assume that your problem is because Exchange assumes that the organizer of the event is also the originator of the event. Which seems fair enough, as otherwise it would be child's play to send meetings to people making them the organizer and they would be added automatically to the person's calendar.
All that said, no idea how to get around the issue.
the behavior of event invitation being sent by email is described in rfc6047 which further extends the icalendar RFC (RFC5545).
section 2 and section 3 on security, summarizes two spoofing threats:
spoofing the "Organizer", and spoofing an "Attendee"
that is
spoof#xyz.example.net is not allowed to modify or cancel a meeting that was organized by a#example.com.
to your case:
did you send the invitation from the same email address as your exchange (talking about the From: in the mail not the Organizer:mailto ? if not it might be worth trying to send it via the exchange address.
should above not work, to address your need for the organizer to have the invitation in its calendar you probably will need to add it programmatically in the organizer's agenda as it is likely that the CUA (Calendar User Agent) or Exchange does not allow a 3rd party mailer to add events in agenda without end-user UI usage.
In recent months ,our service also meet the same problem as you:
our service create meeting calendar for organizer and attendees,
if attendees contains organizer ,organizer (as a atteendee) can get a calendar email,
but it does neither be allowed to receive/reject the meeting(the button is disabled) nor see it in calendar(no calendar event).
finally, I notice that only when under following condition this will happen:
1. mail.From = organizer
2. Ateendees.contains(organizer) //case-insensitive.
So , I simply change my code to follwing , and it works fine for all attendees (include organizer):
if (!attendeeEmail.ToLower().Contains(organizer.Address.ToLower()))
{
message.From = organizer;
}
else
{
//such as your actual email sender, in our case, our mail sender use another email,
//say ActualSender,and if leave empty, then our mail sender will fill as:
message.From = ActualSenderEmail;
}
I have a windows forms application that I am adding a request support form to, and would like the user to be able to input the values and hit a button. Once the button is pushed I can either:
Open a new mail message and auto populate the message. (Not sure how to do this)
Submit the request via a http form on my website. (I know how to do this)
Send an email directly from the code of the application. (I know how to do this)
What I want to know is what would be the best method to use? I think option 1 is the most transparent, and the user will see exactly what is being sent, but I am not sure how to ensure it works no matter what email client they use.
I see there being potential issues with option two, specifically a firewall possibly stopping the submission. But option 2 would allow me to supply them with a ticket number right then and there for their request.
Thanks for the help.
For Option 1, as suggested, use the mailto handler.
Format your string like so: string.Format("mailto:support#example.com?subject={0}&body={1}", subject, body). Don't forget to UrlEncode the subject and body values.
Then use System.Diagnostics.Process.Start() with your string.
This will launch the registered mail handler (Outlook, Windows Live Mail, Thunderbird, etc) on the system.
For option 1 : If the message body is short, then invoking the mailto handler from inside your code no longer requires that they be using outlook. It's kinda a cheap hack, but it's completely cross-platform for local mail clients. (If they're using something like gmail, you're still SOL, though)
Option 2) is the best to avoid enterprise firewall issues because the HTTP port may not be blocked.
Option 2) is the best for simple configuration. The only config key you will have is the service/page url. Then your SMTP configuration will stay on your webserver.
Now you will have to choose between using a webpage (if one already exists) or a webservice (which is best fitted for your feature).
For option (1) be prepared to deal with Outlook version problems. But this is not hard (again if we are talking about Outlook, last version)
//using Microsoft.Office.Interop.Outlook;
private void OutlookMail(string Subject, string Body)
{
ApplicationClass app = new ApplicationClass();
NameSpaceClass ns = (NameSpaceClass)app.GetNamespace("mapi");
ns.Logon("", "", true, true);
MailItem mi =
(MailItem)app.CreateItem(OlItemType.olMailItem);
mi.Subject = Subject;
int EOFPos = Body.IndexOf(char.Parse("\0"));
if (EOFPos != -1)
{
log.Error("EOF found in Mail body");
ErrorDialog ed = new ErrorDialog(TietoEnator.Common.ErrorDialog.ErrorDialog.Style.OK, "Export Error", "File could not be exported correctly, please inform responsible person", "", "EOF char detected in the body of email message.");
ed.ShowDialog();
Body=Body.Replace("\0", "");
}
mi.HTMLBody = "<html><head><META content='text/html; charset=CP1257' http-equiv=Content-Type></head><body><table>"+Body+"</table></body></html>";
mi.BodyFormat = OlBodyFormat.olFormatHTML;//.olFormatPlain;
mi.Display(0); // show it non - modally
ns.Logoff();
}
BTW for automatic support requests I plan to use in my current project "Microsoft Enterprise Logging Support Block" email sending functionality.